How to capture the exit_code and stderr of the command that is run in C++?

后端 未结 3 1865
梦谈多话
梦谈多话 2020-12-31 02:38

I\'m writing a c++ program that executes and outputs (in real-time) a shell script, makefile or just another program. However I would like to have my program return differen

3条回答
  •  礼貌的吻别
    2020-12-31 03:19

    Thanks for the reply about exit code Logan.

    I believe a round-trip to get stderr would be to redirect it to a temporary file:

    FILE* f = popen("cmd 2>/tmp/tmpfile.txt", "r");
    

提交回复
热议问题