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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gaurav kashyap

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

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

    1.py
    import os
    import sys
    processID=os.sp awnl(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
  • Peter Otten

    #2
    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.sp awnl(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

    Comment

    • gaurav kashyap

      #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

      Comment

      Working...