运行时r=Runtime.getRuntime();
进程p=r.exec(“uname-a”);
P.WAITFOR();
BufferedReader b=新的BufferedReader(新的InputStreamReader(p.getInputStream()));
字符串行=“”;
while((line=B.readline())!=null){
System.out.println(行);
}
b.关闭();
//我找到了这个,但是在Java我需要用C++编写
“system”实用程序可用于从C++程序中运行系统命令。
下面是运行命令的工作演示:
// C++ program to run System command
#include <bits/stdc++.h>
using namespace std;
int main () {
string command;
cout << "Enter the command to execute: \n";
getline (cin, command);
cout << "Output:\n";
system(command.c_str());
return 0;
}
输出:
Enter the command to execute:
uname -a
Output:
Linux Check 4.15.0-1044-gcp #70-Ubuntu SMP Mon Sep 16 12:38:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux