Run terminal from Python script

Asked

Viewed 445 times

2

I am doing a work of distributed systems, in which I am using PYRO, in it I am using objeto.adapter.rebindURI() to use the same object when the server that was (dropped) is "restarted"...

I’m hoping that this re-start is from my Python program... in case I thought to call open a new window and run my server program...

Does anyone know how to do it? 'Cause I tried N times and I couldn’t. It makes the following mistake:

Traceback (most recent call last):
  File "serverApp.py", line 7, in <module>
    subprocess.Popen(cmd, stdout=subprocess.PIPE)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I tried something like this...

import subprocess

cmd = ["xterm"]

cmd.extend(['-e','bash','-c','python serverApp.py; exec $SHELL'])
  • Do you have the xterm command installed? The user running the command has access to it?

  • the idea is a script that starts a terminal and the same runs a python script ?.. or just call the terminal

2 answers

0

If xterm is installed, the best way to ensure its execution is to pass its absolute path in the subprocess.

To find the absolute path:

~ which xterm
/usr/bin/xterm

Include this in Python Subprocess:

import subprocess
cmd = ["/usr/bin/xterm"]

0

Apparently Voce doesn’t have xterm installed on your machine.

I believe Voce must be trying to give a subprocess.call in cmd, the command that is executed will be:

$ xterm -e bash -c python serverApp.py; exec $SHELL

Try to run this at your command prompt and probably see the same problem.

I did not understand why Voce would run xterm before. Try to run python directly and see if the problem is not solved.

Ex:

python> subprocess.call(['python', 'serverApp.py'])

Browser other questions tagged

You are not signed in. Login or sign up in order to post.