Skip to content

Instantly share code, notes, and snippets.

@aoleg94
Created June 26, 2019 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoleg94/337fbab219a91648a7d0d162e5a768ef to your computer and use it in GitHub Desktop.
Save aoleg94/337fbab219a91648a7d0d162e5a768ef to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <spawn.h>
#include <sys/wait.h>
int main(int argc, char** argv, char** envp)
{
if(argc < 2)
{
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
return 0;
}
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
pid_t p = -1;
int ret = posix_spawnp(&p, argv[1], 0, 0, argv+1, envp);
if(!ret)
{
int ws = 0;
waitpid(p, &ws, 0);
ret = WEXITSTATUS(ws);
}
SetThreadExecutionState(ES_CONTINUOUS);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment