#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    WA
    Posts
    29
    Rep Power
    0

    Python calls program -- Program requires input


    My python scripts calls a program using subprocess.call()

    The program it calls requires input from the user -- Could I emulate the user typing that in, and pressing enter?

    Like have the python script do it for them?

    Unfortunatly the program doesn't allow putting the input in when you call it -- ie -- 'nano [filename]'

    You can't determine what goes in the file from the cmd line (short of echo 'blah' > [filename]

    Thanks,
    Poz
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    From your post it sounds like you need to manage the input and output steams of the sub-process. Check out the module documentation on this

    grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    If your program just needs a fixed input read from stdin then you can do it with the subprocess module, as grim says.

    If the program needs to interact with your program, for example it prints something and then your program types in a response, then you to use pexpect. This only works on unix systems or cygwin though.

    Dave

IMN logo majestic logo threadwatch logo seochat tools logo