I need some help regarding my C++ program. A batch file named abc.bat is located somewhere in my hardisk. I know that in C++ I can use this line of code to execute that abc.bat file:
system ("file path here\\abc.bat");
I want to send some commands to that batch file so that after executing that abc.bat file my C++ program should write commands to its console and execute them. How can I do that?
You can do this by opening a pipe. In brief:
FILE *bat = popen("path\\abc.bat", "w");
fprintf(bat, "first command\n");
fprintf(bat, "second command\n");
pclose(bat);
The text you write to bat will end up on the standard input of the batch file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With