Search code examples
pythonwxpythonsubprocess

python osx terminal thread with subprocess.Popen


I have a program in Python that uses subprocess and Popen, however when I run a particular binary, an iOS tool called itnl/itunnel, it keeps the terminal window open for logging purposes and therefore I cannot write any further commands to that terminal such as the ssh command.

I have played around with various options including creationflags that I found in another SO thread but it didn't seem to work on OSX.

Running OSX and python 2.7 on homebrew install.

if ("iPhone" in stdout or "iPad" in stdout):
        self.progressBox.AppendText('Device found. Starting iTunnel\n')
        cmd = toolsDir + "/itnl --iport 22 --lport 2222"
        p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdout = p.communicate()[0]
        if "Device connected" in stdout:
            cmd = "ssh -p 2222 [email protected]"
            p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Once itunnel runs it sits there waiting for connections from the device like below:

 [INFO] Waiting for new TCP connection on port 2222
 [INFO] Waiting for device...
 [INFO] Device connected: 6a0a098xxxxxxxx3cb2ef9ef6205

(this is when you type 'ssh etc etc' to complete the connection)


Solution

  • found a way round my issue by sending any output to dev/null and backgrounding the process:

    ./itnl --iport 22 --lport 2222 > /dev/null 2>&1 &
    

    not ideal as I now can't get the stdout to see if a device has connected but it returns me to the terminal prompt and allows further commands.