When running a secondary python script:
subprocess.Popen
, or subprocess.call
or even execfile
in a n
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)
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.
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).