I am experiencing a problem with a C program running on Windows XP that is getting Permission Denied (EACCES) errors when it tries to call system().
It doesn't seem to matter what I put in the command string, the commands all work manually but get Permission Denied errors when executed via system()
The other interesting thing is that the program works correctly on other XP machines, just not this one. That makes it feel like some kind of OS setting, but I am not totally sure what system() does under the hood and would like to understand what is happening here.
Here is my test code:
fprintf( stderr, "DEBUG: Running test of system(NULL) call...\n" );
if ( ( ret = system( NULL ) ) != 0)
fprintf( stderr, " DEBUG: ret: %d: errno: %d, %s\n", ret, errno, strerror( errno ) );
fprintf( stderr, "DEBUG: Running test of system(\"sleep 1\") call...\n" );
if ( ( ret = system( "sleep 1" ) ) != 0 )
fprintf( stderr, " DEBUG: ret: %d: errno: %d, %s\n", ret, errno, strerror( errno ) );
This produces an output of
DEBUG: Running test of system(NULL) call...
DEBUG: ret: 1: errno: 0, No error
DEBUG: Running Test of system("sleep 1") call...
DEBUG: ret: -1: errno: 13, Permission denied
Thanks.
UPDATE: I have also modified my code to use CreateProcess() instead of system(), and I still get an "Access Denied" error (5). This makes it sound even more like an OS setting, but I don't know where to look.
UPDATE2: Process Monitor shows the failure in a call to "QueryOpen" for the path "D:\cmd.exe", which does not exist. All the other calls are for C:\WINDOWS\system32\cmd.exe, so I don't know why the one call is bad.