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. Advertisements

  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. Advertisements

  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. Advertisements

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. Lingyun Yang
    Replies:
    4
    Views:
    12,273
    Keith Dart
    Dec 16, 2004
  2. Derek Basch
    Replies:
    2
    Views:
    1,492
    Donn Cave
    Jan 21, 2005
  3. Daniel Nogradi

    pythonic exec* spawn*

    Daniel Nogradi, Feb 9, 2006, in forum: Python
    Replies:
    9
    Views:
    430
    Nick Craig-Wood
    Feb 13, 2006
  4. Alexandru  Mosoi

    passing arguments to exec

    Alexandru Mosoi, Aug 25, 2008, in forum: Python
    Replies:
    0
    Views:
    410
    Alexandru Mosoi
    Aug 25, 2008
  5. Ed Hames
    Replies:
    0
    Views:
    570
    Ed Hames
    Apr 16, 2008
  6. Edgardo Hames
    Replies:
    1
    Views:
    520
    Ed Hames
    May 6, 2008
  7. ashish
    Replies:
    4
    Views:
    456
    ashish
    Sep 20, 2012
  8. ashish
    Replies:
    5
    Views:
    685
    Piet van Oostrum
    Sep 20, 2012
Loading...