0

I would like to know if it's possible to execute this command

cmd = "gnome-terminal -e 'python /path/to/file.py'"

p = subprocess.Popen(cmd,shell=True)

but with shell=False

I tried to run this command

p = subprocess.Popen(["gnome-terminal","-e","python","/path/to/file.py"],shell = False)

but it's not working:

Thank you!

5
  • 1
    It will just open python, but it will not execute the python script (file.py) @RahulKP Commented Jun 10, 2016 at 15:55
  • Are you trying to execute python file from another python file ? Commented Jun 10, 2016 at 15:57
  • No the python script! @RahulKP Commented Jun 10, 2016 at 15:59
  • Why the downvote though? Commented Jun 10, 2016 at 16:03
  • @RahulKP: it doesn't work: read about the difference between -e and -x options. Commented Jun 12, 2016 at 15:34

1 Answer 1

2

As it is you're passing the command to gnome-terminal, not python.

p = subprocess.Popen(["gnome-terminal","-e","python /path/to/file.py"],shell = False)
Sign up to request clarification or add additional context in comments.

3 Comments

Don't know why I didn't try this, but THANK YOU! :)
@Eliekhalifeh: if you want to pass separate command-line arguments as the command, use -x instead of -e in your code.
@J.F.Sebastian It worked using the above answer, but thank you, I'll keep this in mind!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.