system()控制键盘

时间:2015-06-25 17:23:26

标签: c++ linux c++11

我在Linux上使用C ++。每当我在一个线程中进行system()调用时,它就会控制键盘而我无法使用ctrl + c退出程序。我用系统调用调用的程序是一个SSH命令,在主调用程序退出之前不应该退出。谢谢

2 个答案:

答案 0 :(得分:1)

You probably want to use the Fork-exec technique to launch the SSH command as a separate process; then, from the launching process, you can wait for the child to finish with wait or kill it.

答案 1 :(得分:0)

您也可以通过std::async调用SSH命令,然后返回std::future<T>,其中T可能是void,然后是wait()(或get() ) 在上面。此外,您可以创建std::thread并在其上调用detach()