Running a secondary script in a new terminal

前端 未结 3 1147
暖寄归人
暖寄归人 2021-01-23 03:54

When running a secondary python script:

  • Is it possible to run a subprocess.Popen, or subprocess.call or even execfile in a n
相关标签:
3条回答
  • 2021-01-23 04:15

    If you're using tmux, you can specify which target you want the command to run in:

    tmux send -t foo.0 ls ENTER
    

    So, if you've created a tmux session foo.0, you should be able to do:

    my_command = 'ls'
    tmux_cmd = ['tmux', 'send', '-t', 'foo.0', my_command]
    p = subprocess.Popen(tmux_cmd)
    
    0 讨论(0)
  • 2021-01-23 04:18

    I guess you want something like

    subprocess.call(['xterm','-e','python',script])
    

    Good old xterm has almost no frills; on a Freedesktop system, maybe run xdg-terminal instead. On Debian, try x-terminal-emulator.

    However, making your program require X11 is in most cases a mistake. A better solution is to run the subprocesses with output to a log file (or a socket, or whatever) and then separately run tail -f on those files (in a different terminal, or from a different server over ssh, or with output to a logger which supports rsyslog, or or or ...) which keeps your program simple and modular, free from "convenience" dependencies.

    0 讨论(0)
  • 2021-01-23 04:32

    You can specify the tty of the terminal window you wish the command to be carried out in:

    ls > /dev/ttys004
    

    However, I would recommend going for the tmux approach for greater control (see my other answer).

    0 讨论(0)
提交回复
热议问题