[英]Run a bash script with C++ on Windows
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. 如果不在 Windows 上安装任何额外的软件,这甚至可能吗? 如果是这样,怎么做?
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?
您可以使用popen function。
FILE *fp;
fp = popen("bash script.sh", "r");
现在您可以像读取文件一样读取 output。 例子:
char output[100];
fgets(output, sizeof(output), fp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.