开发者

How can I suppress system output when using nohup from Perl?

In Perl I am starting a process using the nohup command. The command is below:

system("nohup myproc pe88 &");

This works fine and the process starts as expected. However I would like to suppress the following开发者_如何学C output of this command - which is:

Sending output to nohup.out

I must have this process redirecting all of it's output to nohup.out but I just don't want it displayed when I run my Perl program. I want to instead, print my own user friendly message. I've tried a few variants but nothing has worked for me yet.


"Sending output to nohup.out" message is sent to STDERR, so you can catch the STDERR via the usual methods

  • either via shell: system("nohup myproc pe88 2> /tmp/error_log.txt &");

    Use /dev/null instead of /tmp/error_log.txt if you don't need stderr at all; and add "> /tmp/myout.txt" to redirect stdout.

  • Or by capturing via Perl (don't use system() call, instead use IPC::Open3 or capture command from IPC::System::Simple)


How about:

system("nohup myproc pe88 >nohup.out 2>&1 &");

The man page for nohup says:

If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use `nohup COMMAND > FILE'.

So if you explicitly redirect STDOUT and STDERR to nohup.out, then nohup doesn't print that message. Granted, you don't get the automatic fallback to $HOME/nohup.out if nohup.out is unwritable, but you can check for that first if that's an issue.

Note that if you redirect just STDOUT, nohup prints a "redirecting stderr to stdout" message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜