passing a variable to an external program

R

Rich

I want to run an external program using os.system() but I want to
include a variable in the middle of the command line.

An example of the type of thing I want to be able to do:
pathname = os.path.dirname(sys.argv[0])
os.system('cscript /nologo ' + pathname + '\test.vbs')

When I run this, everything after pathname + seems to be ignored. Is
this just incorrect syntax or am I trying to do something fundamentally
wrong? Is there a better way to do something like this? I'm trying to
move from perl to python and this is my first attempt at python.
 
N

Neil Cerutti

I want to run an external program using os.system() but I want to
include a variable in the middle of the command line.

An example of the type of thing I want to be able to do:
pathname = os.path.dirname(sys.argv[0])
os.system('cscript /nologo ' + pathname + '\test.vbs')

Use / instead of \, or \\ instead of \.
 
R

Rich

Thank you, that did it. I don't know why I didn't think to escape the
\ with \\.

I want to run an external program using os.system() but I want to
include a variable in the middle of the command line.
An example of the type of thing I want to be able to do:
pathname = os.path.dirname(sys.argv[0])
os.system('cscript /nologo ' + pathname + '\test.vbs')Use / instead of \, or \\ instead of \.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top