[英]Can't get linux 'exec' command to work properly
I want to use the exec command to run a python script in the background of the current terminal session. 我想使用exec命令在当前终端会话的后台运行python脚本。 Other posts suggest that
其他帖子表明
exec python myscript.py &
should run the script in the background. 应该在后台运行脚本。 However the output of the program is still on my command line.
但是,程序的输出仍在我的命令行上。 Have I misunderstood the exec command?
我是否误解了exec命令? I just want to have the output of the script ignored or if this isn't possible, sent to a file.
我只想忽略脚本的输出,或者如果不可能,则将其发送到文件。
I can't use nohup because I need to send the SIGHUP signal to my script. 我不能使用nohup,因为我需要将SIGHUP信号发送到我的脚本。 Apart from nohup, feel free to suggest other solutions.
除了nohup,请随时提出其他解决方案。
如果要在后台运行命令,则可以使用nohup exec python myscript.py &
,文件的输出存储在nohup.out文件中
Running in the background just means you can interact with the current shell, but the stdout (and stderr) of the background process is still connected to the terminal. 在后台运行只是意味着您可以与当前shell进行交互,但是后台进程的stdout(和stderr)仍连接到终端。 Redirect it somewhere else if you don't want it:
如果不希望将其重定向到其他地方:
exec python myscript.py &>/dev/null &
Also, why do you need exec
? 另外,为什么需要
exec
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.