Reputation: 923
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?
Upvotes: 3
Views: 3466
Reputation: 993343
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.
Upvotes: 3