blob: 73e7e4b562e1f7c76674157191fc3a2624b8d155 [file] [log] [blame] [raw]
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
//#include <sys/wait.h>
//#include <bits/libc-lock.h>
//#include <sysdep-cancel.h>
#include <windows.h>
#define SHELL_PATH L"/Windows/command.exe" /* Path of the shell. */
//#define SHELL_NAME L"command.exe" /* Name to give it. */
/* Execute LINE as a shell command, returning its status. */
static int do_system (const char *line)
{
unsigned long int result;
//pid_t pid;
//struct sigaction sa;
PROCESS_INFORMATION pi;
wchar_t wline[PATH_MAX];
mbstowcs(wline, line, PATH_MAX);
/* Child side. */
wchar_t args[PATH_MAX];
//wcscpy(args, SHELL_NAME);
wcscpy(args, L"/c ");
wcscat(args, wline);
if(!CreateProcessW(SHELL_PATH, args, NULL, NULL, 0, 0, NULL, NULL, NULL, &pi)) return 0;
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &result);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return result;
}
int system (const char *line)
{
if (line == NULL) return do_system ("exit") == 0;
return do_system (line);
}