开发者

run a process in another terminal

开发者 https://www.devze.com 2023-03-02 11:12 出处:网络
I\'m actually running a subprocess from a python program using Popen proc= subprocess.Popen(\"xterm -e python script.py\", shell=True, stdout=subproc开发者_运维技巧ess.PIPE, stderr=subprocess.PIPE)

I'm actually running a subprocess from a python program using Popen

proc= subprocess.Popen("xterm -e python script.py", shell=True, stdout=subproc开发者_运维技巧ess.PIPE, stderr=subprocess.PIPE)

And when this process is running on xterm, we can kill it using Ctrl+C, is there a way to send other signals using (Ctrl+Z and fg,...) to resume and continue the job? Another solution would be running this process in another terminal, without using xterm -e is this possible? Any other solution would be helpful. Thanks


You could do it programatically in psutil

import psutil
p = psutil.Pocesss(proc.pid)
p.suspend()
p.resume()


With Python2.6+

# send ctrl+c
popen.send_signal(signal.SIGINT)
0

精彩评论

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

关注公众号