[英]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.