passing a variable to an external program

Discussion in 'Python' started by Rich, Jan 11, 2007.

  1. Rich

    Rich Guest

    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.
    Rich, Jan 11, 2007
    #1
    1. Advertising

  2. Rich

    Neil Cerutti Guest

    On 2007-01-11, Rich <> 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
    Neil Cerutti, Jan 11, 2007
    #2
    1. Advertising

  3. Rich

    Rich Guest

    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 <> wrote:
    > On 2007-01-11, Rich <> 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
    Rich, Jan 11, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Glenn Mantle
    Replies:
    0
    Views:
    400
    Glenn Mantle
    Jul 28, 2004
  2. Cameron Laird
    Replies:
    5
    Views:
    388
    Rigga
    Oct 10, 2003
  3. Alex Martelli
    Replies:
    10
    Views:
    535
    Rigga
    Oct 11, 2003
  4. pereges
    Replies:
    7
    Views:
    425
    pereges
    Jun 1, 2008
  5. sykth
    Replies:
    1
    Views:
    4,232
Loading...

Share This Page