首页 > 解决方案 > 如何在linux中捕获超时的返回值

问题描述

谁能告诉我如何捕获timeout实用程序的输出。正如我在下面捕获的那样,但它没有达到预期的效果。

std::string syscommand = "timeout -s KILL 1s command";
int res = system(syscommand.c_str());
std::cout << res;

当我浏览了一些帖子时,我发现输出应该如下所示。

    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

以及如何打印错误。

标签: c++linuxshellc++11

解决方案


推荐阅读