How to get inputs for a python program that run from another python program

Discussion in 'Python' started by pradeep nair, Jun 11, 2007.

  1. pradeep nair

    pradeep nair Guest

    I would like to know how to pass keyboard input for a python script
    which is ran by another script.

    for eg:

    hello1.py:

    import os

    if __name__=='__main__':

    print "I will call this other program called hello.py"
    os.system("python hello.py")
    print "hello1.py"


    hello.py:

    import os

    if __name__=='__main__':

    print "press ENTER to display"
    #code wer if the user hits enter
    print "hello"
    #else the user hits any other keyboard button:
    sys.exit()


    now wen i run hello1.py,i want the some function or utility in
    hello1.py that can pass the keyboard i/p to hello.py .
     
    pradeep nair, Jun 11, 2007
    #1
    1. Advertising

  2. Re: How to get inputs for a python program that run from anotherpython program

    Hi

    pradeep nair schrieb:
    > now wen i run hello1.py,i want the some function or utility in
    > hello1.py that can pass the keyboard i/p to hello.py .


    Have a look at subprocess.Popen

    http://docs.python.org/lib/module-subprocess.html

    --
    René
     
    =?UTF-8?B?UmVuw6kgRmxlc2NoZW5iZXJn?=, Jun 11, 2007
    #2
    1. Advertising

  3. pradeep nair

    Guest

    On Jun 11, 7:47 am, pradeep nair <> wrote:
    > I would like to know how to pass keyboard input for a python script
    > which is ran by another script.
    >
    > for eg:
    >
    > hello1.py:
    >
    > import os
    >
    > if __name__=='__main__':
    >
    > print "I will call this other program called hello.py"
    > os.system("python hello.py")
    > print "hello1.py"
    >
    > hello.py:
    >
    > import os
    >
    > if __name__=='__main__':
    >
    > print "press ENTER to display"
    > #code wer if the user hits enter
    > print "hello"
    > #else the user hits any other keyboard button:
    > sys.exit()
    >
    > now wen i run hello1.py,i want the some function or utility in
    > hello1.py that can pass the keyboard i/p to hello.py .


    Using pexpect: http://pexpect.sourceforge.net/

    hello1.py:

    import pexpect

    if __name__=='__main__':

    print "I will call this other program called hello.py"

    child = pexpect.spawn('python hello.py')
    child.expect ('\n')

    print "Received from hello.py: ", child.before

    entered = raw_input("> ")
    child.sendline (entered)
    child.expect ('\n')

    print "Received from hello.py: ", child.before
     
    , Jun 12, 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. Willem Oosthuizen

    Coding style to prioritize certain inputs

    Willem Oosthuizen, Sep 2, 2003, in forum: VHDL
    Replies:
    5
    Views:
    513
    Mike Treseler
    Sep 4, 2003
  2. Max

    pullup on inputs

    Max, Sep 25, 2003, in forum: VHDL
    Replies:
    0
    Views:
    628
  3. Max

    R: pullup on inputs

    Max, Sep 25, 2003, in forum: VHDL
    Replies:
    0
    Views:
    531
  4. Alex Fraser
    Replies:
    1
    Views:
    324
    Zuan Chen
    Jun 30, 2004
  5. Robert Macy
    Replies:
    10
    Views:
    791
    Robert Macy
    Jul 16, 2005
Loading...

Share This Page