【问题标题】:How to redirect stderr and run in background with popen()?如何使用popen()重定向stderr并在后台运行?
【发布时间】:2018-04-20 07:32:58
【问题描述】:

我可以做一个或另一个,但不能同时做。如果我使用 & 号使其在后台运行,那么它会按预期工作:

popen( "gzip -dc diskImageFile.gz | dd bs=32000000 of=/dev/sd%c status=progress &" );

如果我将它设置为将 stderr 重定向到 stdout,那么它会按预期工作:

popen( "gzip -dc diskImageFile.gz | dd bs=32000000 of=/dev/sda status=progress 2>&1" );

但如果我同时尝试两者,它就不再在后台运行。如何同时做stderr的重定向和后台运行?

popen( "gzip -dc diskImageFile.gz | dd bs=32000000 of=/dev/sda status=progress 2>&1 &" );

我在 Raspberry Pi (Debian) 上执行此操作

【问题讨论】:

    标签: c++ linux debian popen


    【解决方案1】:

    popen 启动另一个独立于调用进程运行的进程。没有必要让那个 & 号在后台运行它,它已经这样做了。

    【讨论】:

    猜你喜欢
    • 2011-09-20
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 2015-11-20
    • 2017-02-14
    • 2011-08-20
    • 2018-12-13
    • 2018-08-24
    相关资源
    最近更新 更多