Are the OS (XP) environmental variables the same used in a process running from visual studio .NET C++?
It seems the command interpreter is not found:
When using NULL as the command, system() returns 0 and with command - ENOENT Command interpreter cannot be found
.
In windows (System->Environmental Variables), COMSPEC contains the path to cmd.exe
PATH does not.
What should PATH be?
Other than this, not sure why it can not find the interpreter.
Any suggestions are appreciated. Thanks.
if( system("tail -500 log.txt") == -1)
{
//Error calling tail.exe on log
//errno is a system macro that expands int returning
//the last error. strerror() converts the error to it's
//corresponding error message.
printf("Error calling tail.exe with system(): %s",strerror( errno ));
}
EDIT1
Stepping into system() argv[0] = _tgetenv(_T("COMSPEC"));
returns a bad pointer. Being this is a cgi executable, the COMPSEC is not properly set or inherited from the OS.
I now set COMSPEC before the process is started and use CreateProcess() as in example 2
However, create process still returning 0? Getting closer. See any issues with this? Thanks.
if (! SetEnvironmentVariable("COMSPEC", "C:\\WINDOWS\\system32\\cmd.exe") )
{
printf("SetEnvironmentVariable failed (%d)\n", GetLastError());
}
//r = system("dir c:\\");
r = CreateProcess("dir.exe", NULL, NULL, NULL, TRUE, NULL,
NULL, // inherit parent's environment
NULL, &si, &pi);
EDIT 2
SetEnvironmentVariable() did not work. However, putenv does.
_putenv( "COMSPEC=C:\\WINDOWS\\system32\\cmd.exe" ); // C4996
Not sure what the difference is...?
Now that this env var is set, any request on the cgi app from the browser gives the option to save the cgi.exe instead of executing it.. Not sure why this has changed based on this env var?