1

I have a shell that is opened and I'm running some commands there. my python file should also run 1 command there
How can I do it without opening this shell again ? (I want to use the already opened one) thanks a lot!

editing : It's an .exe that I compiled and i'm opening and running some "init" functions. I want my python script for example to to something like: "func(path to the .exe, commans to execute)" and when using the path - it will use the exsiting .exe

3
  • Which OS? What sort of shell? Commented Nov 7, 2013 at 13:56
  • Could you clarify on what you mean? Are you typing commands into this window? Do you want your python script to respond based on a command? or also be issuing commands? Commented Nov 7, 2013 at 13:57
  • What have your tried? Commented Nov 7, 2013 at 15:25

1 Answer 1

3

Use the subprocess module:

import subprocess
subprocess.call("shell commands go in here")

This will execute shell commands from within the location of your Python script. Example:

import subprocess
subprocess.call(["ping", "www.google.com"])
PING www.google.com (178.59.100.242) 56(84) bytes of data.
64 bytes from cache.google.com (178.59.100.242): icmp_req=1 ttl=54 time=19.1 ms
Sign up to request clarification or add additional context in comments.

Comments

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.