Search code examples
pythonsubprocesstmux

executing a tmux command normally containing '\;' using subprocess.run


First of all, yes. I did read a few questions concerning this issue, and I do understand that escaping should be unnecessary (I even specified shell=False).

my issue is that

subprocess.run(['tmux', '-n top', 'top', '; neww'])

causes a tmux session to open and immediately close

I am trying to achieve the same result as executing

tmux new -n top top \; neww

in the shell.

I have also tried specifying shell=True and using '\\; neww' as well as r'\; neww'

it does not appear that anything is being written to stderr either.


Solution

  • Each argument needs to be individual:

    >>> import subprocess
    >>> subprocess.run(['tmux', 'new', '-d', '-n', 'top', 'top', ';', 'neww'])
    CompletedProcess(args=['tmux', 'new', '-d', '-n', 'top', 'top', ';', 'neww'], returncode=0)
    >>>