使用 (cin) 用户输入将其粘贴到 std::system 中,并在另一个终端中运行带有输入的命令
Use the (cin) user input to paste it in std::system and run a command with the input in another terminal
使用 (cin( 用户输入将其粘贴到 std::system 中,并在另一个终端中使用输入运行命令
int main() {
string ip;
cout << "IP to scan: ";
cin >> ip;
std::system(" nmap .... ")
return 0;
}
所以基本上我希望字符串 ip 在 gnome ternimal 中使用,这样我就可以对用户键入的 ip 进行例如 nmap 扫描
这可以使用字符串格式轻松完成:
int main() // ; << Note this is wrong!
{
string ip;
cout << "IP to scan: ";
cin >> ip;
std::ostringstream os;
os << "nmap " << ip;
std::system(os.str().c_str());
// return 0; isn't necessary
}
要在不同的终端窗口中运行该命令,您必须使用system()
调用终端程序,正如 scheff 在他们的评论中提到的那样
os << "gterm -e "nmap " << ip """;
std::system(os.str().c_str());
相关文章:
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- C++ 如何打开带有另一个目录的输入文件?
- 一个变量的输入值也会保存到另一个变量中
- 如何使用函数将一个对象的输入复制到另一个对象中
- 如何设置默认参数以防用户不输入另一个参数
- C++ 如何根据作为输入传递的参数调用一个构造函数或另一个构造函数?
- 在一个子程序中输入的变量用于C++中的另一个子程序
- 使用 (cin) 用户输入将其粘贴到 std::system 中,并在另一个终端中运行带有输入的命令
- 为什么在我的程序中输入另一个输入会给我不同的结果
- GoogleMock:如何根据另一个输入参数设置ArgReferee?
- 如何在 eclipse 中将标准输入从控制台更改为另一个程序
- 如何从C++的输入中查找字符串并将其替换为另一个字符串
- 如何将文件复制到另一个文件中,但是用用户输入的单词替换单词
- C 将用户输入从一个函数到另一个功能,并使用Main(Newbie)显示
- 如何从另一个线程停止 std::cin 再读取输入?
- C++:为什么这个字符串输入失败,而另一个没有
- "cin.get"停止了另一个输入函数,如"cin"..C++
- 只有当输入文件确实包含要读取的另一个值时,我才能让getline(variable,n)运行
- 如何在C 中的另一个对象的同一数据成员中输入另一个字符串
- getline(cin,aString)接收输入而不输入另一个值