Executing a file or program

May 3, 2015 at 1:55pm
Hi
Is there a way I can lunch/execute a program or text file with my cpp code?
May 3, 2015 at 4:14pm
I know I will be hit by other guys in this Forum but if you are operating on Windows and you want an easy solution you could use system.

1
2
3
4
5
6
7
8
#include <stdlib.h>

int main()
{
    system("test.exe");

    return 0;
}
Last edited on May 3, 2015 at 4:17pm
May 3, 2015 at 4:27pm
Nothing wrong with using system, just keep in mind in the future if you want to call other programs you may want to consider other methods because system can fail to call what you want to call depending on the environment variables (PATH) and some other factors (some malicious)

Consider using CreateProcess for executables
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

For binary files you can open them with fstream
http://www.cplusplus.com/reference/fstream/fstream/
Last edited on May 3, 2015 at 4:27pm
May 5, 2015 at 8:07pm
system("test.exe");
worked just fine tnx
Topic archived. No new replies allowed.