This question talks about using the system command and passing variables. Here is an example it gives:
string cmd("curl -b cookie.txt -d test=");
cmd += line;
cmd += " http://example.com";
system(cmd.c_str());
One of the comments mentions that if line was passed and contained foo & fire_nukes.exe & REM then it’s quite possible something bad could happen.
PHP has a great function called escape_shell_args which can be used to escape parameters that are being passed to the program. Does C++ have a way to do that?
The best way is not to use
system()at all. Usefork()andexec()and friends.Here’s an example: