passing arguments from a python program to other while executing itwith exec() or spawn() in LINUX

Discussion in 'Python' started by gaurav kashyap, Oct 16, 2008.

  1. HI all,
    i have two python programs as 1.py and 2.py

    1.py
    import os
    import sys
    processID=os.spawnl(os.P_WAIT,'/usr/local/bin/python','python','/
    mywork/2.py ' + 'hi')

    2.py
    import sys
    domain= str(sys.argv[1] )
    print domain

    IN LINUX
    while executing 1.py,the argument 'hi' is not passed to the 2.py and
    error message is displayed as :
    python: can't open file '/mywork/2.py'.If i execute the program from
    shell like:
    python 2.py hi,then it works fine


    IN WINDOWS
    this is working fine

    PLEASE HELP.
    thanks
    gaurav
     
    gaurav kashyap, Oct 16, 2008
    #1
    1. Advertising

  2. gaurav kashyap

    Peter Otten Guest

    Re: passing arguments from a python program to other while executing it with exec() or spawn() in LINUX

    gaurav kashyap wrote:

    > HI all,
    > i have two python programs as 1.py and 2.py
    >
    > 1.py
    > import os
    > import sys
    > processID=os.spawnl(os.P_WAIT,'/usr/local/bin/python','python','/
    > mywork/2.py ' + 'hi')
    >
    > 2.py
    > import sys
    > domain= str(sys.argv[1] )
    > print domain
    >
    > IN LINUX
    > while executing 1.py,the argument 'hi' is not passed to the 2.py and
    > error message is displayed as :
    > python: can't open file '/mywork/2.py'.


    Did you cut and paste that? I would expect the message to be

    python: can't open file '/mywork/2.py hi'.

    or similar, i. e. the script name is assumed to be '/mywork/2.py hi'. You
    have to pass arguments to the 2.py script as separate arguments to
    os.spawnl()

    os.spawnl(os.P_WAIT,'/usr/local/bin/python','python','/mywork/2.py', 'hi')

    Peter
     
    Peter Otten, Oct 16, 2008
    #2
    1. Advertising

  3. Re: passing arguments from a python program to other while executingit with exec() or spawn() in LINUX

    Thanks for the help Peter.Its working fine now
     
    gaurav kashyap, Oct 16, 2008
    #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. Derek Basch
    Replies:
    2
    Views:
    1,314
    Donn Cave
    Jan 21, 2005
  2. Ed Hames
    Replies:
    0
    Views:
    388
    Ed Hames
    Apr 16, 2008
  3. Edgardo Hames
    Replies:
    1
    Views:
    366
    Ed Hames
    May 6, 2008
  4. ashish
    Replies:
    4
    Views:
    302
    ashish
    Sep 20, 2012
  5. ashish
    Replies:
    5
    Views:
    532
    Piet van Oostrum
    Sep 20, 2012
Loading...

Share This Page