C++ linux中如何捕获超时的返回值
请告诉我如何捕获C++ linux中如何捕获超时的返回值,c++,linux,shell,c++11,C++,Linux,Shell,C++11,请告诉我如何捕获timeout实用程序的输出。 正如我在下面捕捉到的一样,但它并没有达到预期的效果 std::string syscommand = "timeout -s KILL 1s command"; int res = system(syscommand.c_str()); std::cout << res; p>如何打印错误,为什么在没有C++ C++的问题中,代码>代码:ST::String < /代码>(C++的东西)?也许你想要。你的问题不清楚。直接阅读并考虑使
timeout
实用程序的输出。
正如我在下面捕捉到的一样,但它并没有达到预期的效果
std::string syscommand = "timeout -s KILL 1s command";
int res = system(syscommand.c_str());
std::cout << res;
<> p>如何打印错误,为什么在没有C++ C++的问题中,代码>代码:ST::String < /代码>(C++的东西)?也许你想要。你的问题不清楚。直接阅读并考虑使用系统调用,如“代码>管道<代码>,<代码> Foe<代码>,<代码>执行> <代码>,<代码> Poope<代码>,<代码> WaistPID < /C>。请看这篇文章。如果您不清楚,请不要给出-1。如果您阅读了引用的手册页,您会发现需要使用
WIFEXITED
和WEXITSTATUS
宏来获取退出代码。另外,你的问题需要解释什么不起作用。你期待什么?你得到了什么?
124 if command times out
125 if timeout itself fails
126 if command is found but cannot be invoked
127 if command cannot be found
137 if command is sent the KILL(9) signal (128+9)
the exit status of command otherwise