Calling python script in dos and passing arguments

P

PEnergy

Greetings,

I am trying to write a python script that, when called from the DOS prompt, will call another python script and pass it input variables. My current code will open the other python script but doesn't seem to pass it any values:

import os,sys,subprocess
subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*'])

Am I missing something or is this type of call not possible through DOS?

Thanks,
PEnergy
 
C

Chris Rebert

Greetings,

I am trying to write a python script that, when called from the DOS prompt, will call another python script and pass it input variables. My current code will open the other python script but doesn't seem to pass it any values:

import os,sys,subprocess
subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*'])

Am I missing something or is this type of call not possible through DOS?

1. Backslash is an escape character in Python strings (e.g. "\n" =
newline). You should therefore double-up on your backslashes. (Your
exact string just so happens to work due to a misfeature regarding how
invalid backslash escapes are handled.)
2. Glob/wildcard ("*") expansion is done by the shell, but
subprocess.Popen does not use the shell by default (for good reason!).
Use the `glob` library to do the expansion yourself, in Python:
http://docs.python.org/2/library/glob.html

Cheers,
Chris
 
M

Michael Torrie

Greetings,

I am trying to write a python script that, when called from the DOS
prompt, will call another python script and pass it input variables.
My current code will open the other python script but doesn't seem to
pass it any values:

import os,sys,subprocess
subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*'])

I find it easier just to write my python programs such that they can be
imported into other python scripts. Usually I use this form:

def func(*whatever):
pass

if __name__ == "__main__":
# parse command-line arguments
# call functions in this module with those args
func(1,2,3,etc)

This way a script can be run standalone, or I can import it and access
its attributes direction. I recommend you consider this approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top