The python script I would use (source code here) would parse some arguments when called from the command line. However, I have no access to the Windows command prompt (cmd.exe) in my environment. Can I call the same script from within a Python console? I would rather not rewrite the script itself.
-
try to install python on your windows PC and add it at your environment.... http://stackoverflow.com/questions/1449494/how-do-i-install-python-packages-on-windows – angel May 21 '14 at 12:48
-
See also http://stackoverflow.com/questions/11744181/running-python-script-inside-ipython if you are using iPython as your console. – Wolf May 21 '14 at 12:51
-
@Wolf Simply '%run' does the trick, thanks! Are there any pitfalls to that? Otherwise feel free to write up a a quick answer about it, I am happy to give you credit! – László May 21 '14 at 13:00
3 Answers
%run
is a magic in IPython that runs a named file inside IPython as a program almost exactly like running that file from the shell. Quoting from %run?
referring to %run file args
:
This is similar to running at a system prompt python file args
,
but with the advantage of giving you IPython's tracebacks, and of
loading all variables into your interactive namespace for further use
(unless -p is used, see below). (end quote)
The only downside is that the file to be run must be in the current working directory or somewhere along the PYTHONPATH
. %run
won't search $PATH
.
%run
takes several options which you can learn about from %run?
. For instance: -p
to run under the profiler.

- 4,254
- 1
- 21
- 30
You want to spawn a new subprocess.
There's a module for that: subprocess
Examples:
Basic:
import sys
from subprocess import Popen
p = Popen(sys.executable, "C:\test.py")
Getting the subprocess's output:
import sys
from subprocess import Popen, PIPE
p = Popen(sys.executable, "C:\test.py", stdout=PIPE)
stdout = p.stdout
print stdout.read()
See the subprocess API Documentation for more details.

- 18,669
- 3
- 49
- 62
If you can make system calls, you can use:
import os
os.system("importer.py arguments_go_here")

- 6,732
- 3
- 19
- 20