muta...@gmail.com
2021-04-24 07:05:25 UTC
Hi.
I have my own system() function:
__PDPCLIB_API__ int system(const char *string)
{
BOOL rc;
PROCESS_INFORMATION pi;
STARTUPINFO si;
DWORD ExitCode;
char cmdbuf[300];
if (strlen(string) > sizeof cmdbuf - 10)
{
printf("command %s too long\n", string);
return (-1);
}
strcpy(cmdbuf, "/c ");
strcat(cmdbuf, string);
memset(&si, 0, sizeof si);
si.cb = sizeof si;
memset(&pi, 0, sizeof pi);
/*strcpy(cmdbuf, "/c mybat");*/
printf("cmdbuf is %s\n", cmdbuf);
rc = CreateProcessA("cmd.exe",
cmdbuf,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi);
if (!rc)
{
printf("last error is %d\n", (int)GetLastError());
return (GetLastError());
}
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &ExitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return (ExitCode);
}
and it is printing:
cmdbuf is /c dir
last error is 2
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.
I've tried a variety of things without success, such
as executing a batch file. I'm always getting a return
code of 2:
As far as I can tell, I am executing it according to
the instructions:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
system("dir"); works on other people's compilers.
Any ideas?
Thanks. Paul.
I have my own system() function:
__PDPCLIB_API__ int system(const char *string)
{
BOOL rc;
PROCESS_INFORMATION pi;
STARTUPINFO si;
DWORD ExitCode;
char cmdbuf[300];
if (strlen(string) > sizeof cmdbuf - 10)
{
printf("command %s too long\n", string);
return (-1);
}
strcpy(cmdbuf, "/c ");
strcat(cmdbuf, string);
memset(&si, 0, sizeof si);
si.cb = sizeof si;
memset(&pi, 0, sizeof pi);
/*strcpy(cmdbuf, "/c mybat");*/
printf("cmdbuf is %s\n", cmdbuf);
rc = CreateProcessA("cmd.exe",
cmdbuf,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi);
if (!rc)
{
printf("last error is %d\n", (int)GetLastError());
return (GetLastError());
}
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &ExitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return (ExitCode);
}
and it is printing:
cmdbuf is /c dir
last error is 2
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
ERROR_FILE_NOT_FOUND
2 (0x2)
The system cannot find the file specified.
I've tried a variety of things without success, such
as executing a batch file. I'm always getting a return
code of 2:
As far as I can tell, I am executing it according to
the instructions:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
system("dir"); works on other people's compilers.
Any ideas?
Thanks. Paul.