Reputation: 19
I am trying to write a program in C++ that can execute a bash script on Windows and then read the output of the bash script and store it into a string or something like that. Is this even possible without installing any extra software on Windows? If so, how?
Also, would it work if I wrote the program on Linux with a Posix library and then cross-compiled the C++ program for Windows inside Linux and then move it over to Windows where it needs to execute the bash script?
Upvotes: 0
Views: 1174
Reputation: 301
You can use the popen function.
FILE *fp;
fp = popen("bash script.sh", "r");
Now you can read the output just like you would read a file. Example:
char output[100];
fgets(output, sizeof(output), fp);
Upvotes: 1