Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > passing a variable to an external program

Reply
Thread Tools

passing a variable to an external program

 
 
Rich
Guest
Posts: n/a
 
      01-11-2007
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.

 
Reply With Quote
 
 
 
 
Neil Cerutti
Guest
Posts: n/a
 
      01-11-2007
On 2007-01-11, Rich <(E-Mail Removed)> wrote:
> 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 \.

--
Neil Cerutti
Ushers will eat latecomers. --Church Bulletin Blooper
 
Reply With Quote
 
 
 
 
Rich
Guest
Posts: n/a
 
      01-11-2007
Thank you, that did it. I don't know why I didn't think to escape the
\ with \\.

On Jan 11, 2:18 pm, Neil Cerutti <(E-Mail Removed)> wrote:
> On 2007-01-11, Rich <(E-Mail Removed)> wrote:
>
> > 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 \.

>
> --
> Neil Cerutti
> Ushers will eat latecomers. --Church Bulletin Blooper


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a javascript variable to an external xsl/xml file sykth XML 1 10-11-2009 12:18 PM
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
Passing an external variable via .net into an XSL stylesheet Glenn Mantle ASP .Net 0 07-28-2004 04:24 PM
Variable passing to external program - How?? Alex Martelli Python 10 10-11-2003 07:22 PM
How do I pass a variable to an external program Cameron Laird Python 5 10-10-2003 08:24 PM



Advertisments