I'm missing something obvious here. I am using the DJGPP C compiler. I can successfully open executables, but not files in their default programs.
#include <stdio.h>
int main(void) {
char sys_cmd[100] = "C:\\WINDOWS\\system32\\Calc.exe";
system(sys_cmd);
system("\"C:\\TextFile.txt\"");
system("\"www.bbc.co.uk\"");
getch();
return 0;
}
Running this code causes the calculator to start up. Upon closing the calculator it reports:
Bad command of file name
Bad command of file name
So there is an issue with the other two system calls. I have tried adding "START " to the system call but that doesn't fix it. Having just searched my Windows 7 Pro system it doesn't have a START.EXE. Adding "cmd.exe " just starts cmd, so it's as if no arguments are sent.
I can type "C:\TextFile.txt" into cmd normally and it will open notepad.exe with TextFile.txt openned inside.
Ideally I'd use something safer than system() to do this anyway, but I haven't seen any examples of ShellExecute in DJGPP.