How to Write a Script C++ to Open a Batch File
Run batch file from C++ code
Hi All,
I want to run a batch file from specific environment in my sample C++ code.
Bellow are the steps:
1. open a environment specific command prompt
2. then need to run a batch file.
Could anyone please help me here?
Regards,
Akash
Environment programs can be invoked with std::system() of the <cstdlib> header.
Running a batch file would at my environment be:
| |
Last edited on
The phrase "batch file" typically means "on Windows."
The system() call specifically starts an instance of sh on *nixen, and cmd.exe on Windows, passing your string as argument. Hence:
/bin/sh -c your_string
%ComSpec% /C your_string
Obviously, this means that the operating environment invoked by system() is OS-dependent. Some users my (unwisely) substitute another shell for /bin/sh or cmd.exe. If you wish to be extra pedantic, you can specify the shell as nuderobmonkey did — just be path-specific so that you don't suffer from path injection vulnerabilities:
std::system( "/bin/csh -c my_shell_file.csh" ); // Yes, the (in)famous C-shellHere's something to play with:
| |
0 Response to "How to Write a Script C++ to Open a Batch File"
Postar um comentário