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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pradeep nair

    #1

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

    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__=='__ma in__':

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


    hello.py:

    import os

    if __name__=='__ma in__':

    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 .

  • =?UTF-8?B?UmVuw6kgRmxlc2NoZW5iZXJn?=

    #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.Pope n

    Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve...


    --
    René

    Comment

    • pyscottishguy@hotmail.com

      #3
      Re: How to get inputs for a python program that run from another python program

      On Jun 11, 7:47 am, pradeep nair <deep...@gmail. comwrote:
      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__=='__ma in__':
      >
      print "I will call this other program called hello.py"
      os.system("pyth on hello.py")
      print "hello1.py"
      >
      hello.py:
      >
      import os
      >
      if __name__=='__ma in__':
      >
      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__=='__ma in__':

      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


      Comment

      Working...