阅读背景:

C++执行Linux Bash命令

来源:互联网 
方法一:fopen()函数 #include<cstdlib> #include<string> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N = 300; void Test(void){ char line[N]; FILE *fp; string cmd = "ps -ef| grep java | awk '{print }'"; ////引号内是你的linux指令 // 系统调用 const char *sysCommand = cmd.data(); if ((fp = popen(sysCommand, "r")) == NULL) { cout << "error" << endl; return; } while (fgets(line, sizeof(line)-1, fp) != NULL){ cout << line ; } pclose(fp); } int main(){ Test(); return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 方法一:fopen()函数 #include<cstdlib> #include<strin



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: