I am running Windows 8, and I'm using cygwin to compile my code. I'm trying to run command line commands using the system() command. This seems like it should be simple, but amazingly I couldn;t turn anything up on it. Below is my code:
#include <stdio.h>
#include <string.h>
int main ()
{
char command[50];
int error = 0;
strcpy( command, "cd c:/");
error = system(command);
printf("%s\n", command);
printf("%d\n", error);
while(1)
{
;
}
return(0);
}
However, the above program just returns the variable error as "127" and the variable command as "cd c:/". Some google searching on exit codes showed that this meant that the "127" means the command was not found. I'm totally lost. I've searched for a while, but I can only find questions on this issue relating to C#. How do I run command line commands from a c program?
EDIT: I tried running the program from the cygwin command line and it runs fine. It just runs incorrectly from the normal cmd.exe and when I double-click on the .exe file.