python system subprocess win32

Discussion in 'Python' started by mclaugb, Aug 7, 2007.

  1. mclaugb

    mclaugb Guest

    Hello ALl,
    I have a compiled program "conv.exe" that works as follows:
    >>conv.exe

    -----------------------------
    Please selection from the following options. press "h" for help, "p" for
    print, "r" for readfile.
    Enter your request now:
    ....
    --------------------
    Is there a way to script python using the subprocess method to start this
    program "conv.exe" and then send a "r" to the command line to make it, say,
    readfile.

    I have tried the following but the .communicate("r) is not doing anything

    import subprocess
    import time

    a=subprocess.Popen("c:\\mcml\\conv.exe")
    time.sleep(1)
    (stdout, stderr) = a.communicate("r")

    Many thanks,
    Bryan
    mclaugb, Aug 7, 2007
    #1
    1. Advertising

  2. mclaugb

    Guest

    On Aug 7, 9:48 am, "mclaugb" <> wrote:
    > Hello ALl,
    > I have a compiled program "conv.exe" that works as follows:>>conv.exe
    >
    > -----------------------------
    > Please selection from the following options. press "h" for help, "p" for
    > print, "r" for readfile.
    > Enter your request now:
    > ...
    > --------------------
    > Is there a way to script python using the subprocess method to start this
    > program "conv.exe" and then send a "r" to the command line to make it, say,
    > readfile.
    >
    > I have tried the following but the .communicate("r) is not doing anything
    >
    > import subprocess
    > import time
    >
    > a=subprocess.Popen("c:\\mcml\\conv.exe")
    > time.sleep(1)
    > (stdout, stderr) = a.communicate("r")
    >
    > Many thanks,
    > Bryan


    Use the sys.argv method. In the code that you have compiled, put the
    following lines in:

    <code>

    import sys
    default = sys.argv[1]
    if default:
    # check which option it is and run it appropriately
    else:
    # print your menu here

    </code>

    Then you should be able to do the subprocess Popen command:

    subprocess.Popen("c:\\mcml\\conv.exe r")

    You may need to turn the shell on...

    subprocess.Popen("c:\\mcml\\conv.exe r", shell=True)

    Hopefully that gives you some ideas anyway.

    Mike
    , Aug 7, 2007
    #2
    1. Advertising

  3. mclaugb

    mclaugb Guest

    At the moment, I cannot figure a way of running this precompiled "conv.exe"
    using commandline arguments.

    Thus, I need Python to call the program, wait until it loads up, then enter
    a known sequence of characters so that the function will run.
    The program conv.exe I call looks like this.
    --------------------------
    Welcome to conv.exe
    This program was written by ....

    Please select from the following options: h- (help) r- (read) ...etc
    Enter your request:
    ---------------------------------
    I need Python to start the program, wait a second and then issue a few
    characters to the program.

    Hope this makes more sense!
    Bryan

    <> wrote in message
    news:...
    > On Aug 7, 9:48 am, "mclaugb" <> wrote:
    >> Hello ALl,
    >> I have a compiled program "conv.exe" that works as follows:>>conv.exe
    >>
    >> -----------------------------
    >> Please selection from the following options. press "h" for help, "p" for
    >> print, "r" for readfile.
    >> Enter your request now:
    >> ...
    >> --------------------
    >> Is there a way to script python using the subprocess method to start this
    >> program "conv.exe" and then send a "r" to the command line to make it,
    >> say,
    >> readfile.
    >>
    >> I have tried the following but the .communicate("r) is not doing anything
    >>
    >> import subprocess
    >> import time
    >>
    >> a=subprocess.Popen("c:\\mcml\\conv.exe")
    >> time.sleep(1)
    >> (stdout, stderr) = a.communicate("r")
    >>
    >> Many thanks,
    >> Bryan

    >
    > Use the sys.argv method. In the code that you have compiled, put the
    > following lines in:
    >
    > <code>
    >
    > import sys
    > default = sys.argv[1]
    > if default:
    > # check which option it is and run it appropriately
    > else:
    > # print your menu here
    >
    > </code>
    >
    > Then you should be able to do the subprocess Popen command:
    >
    > subprocess.Popen("c:\\mcml\\conv.exe r")
    >
    > You may need to turn the shell on...
    >
    > subprocess.Popen("c:\\mcml\\conv.exe r", shell=True)
    >
    > Hopefully that gives you some ideas anyway.
    >
    > Mike
    >
    mclaugb, Aug 7, 2007
    #3
  4. mclaugb

    Guest

    On Aug 7, 11:07 am, "mclaugb" <> wrote:
    > At the moment, I cannot figure a way of running this precompiled "conv.exe"
    > using commandline arguments.
    >
    > Thus, I need Python to call the program, wait until it loads up, then enter
    > a known sequence of characters so that the function will run.
    > The program conv.exe I call looks like this.
    > --------------------------
    > Welcome to conv.exe
    > This program was written by ....
    >
    > Please select from the following options: h- (help) r- (read) ...etc
    > Enter your request:
    > ---------------------------------
    > I need Python to start the program, wait a second and then issue a few
    > characters to the program.
    >
    > Hope this makes more sense!
    > Bryan
    >
    > <> wrote in message
    >
    > news:...
    >
    > > On Aug 7, 9:48 am, "mclaugb" <> wrote:
    > >> Hello ALl,
    > >> I have a compiled program "conv.exe" that works as follows:>>conv.exe

    >
    > >> -----------------------------
    > >> Please selection from the following options. press "h" for help, "p" for
    > >> print, "r" for readfile.
    > >> Enter your request now:
    > >> ...
    > >> --------------------
    > >> Is there a way to script python using the subprocess method to start this
    > >> program "conv.exe" and then send a "r" to the command line to make it,
    > >> say,
    > >> readfile.

    >
    > >> I have tried the following but the .communicate("r) is not doing anything

    >
    > >> import subprocess
    > >> import time

    >
    > >> a=subprocess.Popen("c:\\mcml\\conv.exe")
    > >> time.sleep(1)
    > >> (stdout, stderr) = a.communicate("r")

    >
    > >> Many thanks,
    > >> Bryan

    >
    > > Use the sys.argv method. In the code that you have compiled, put the
    > > following lines in:

    >
    > > <code>

    >
    > > import sys
    > > default = sys.argv[1]
    > > if default:
    > > # check which option it is and run it appropriately
    > > else:
    > > # print your menu here

    >
    > > </code>

    >
    > > Then you should be able to do the subprocess Popen command:

    >
    > > subprocess.Popen("c:\\mcml\\conv.exe r")

    >
    > > You may need to turn the shell on...

    >
    > > subprocess.Popen("c:\\mcml\\conv.exe r", shell=True)

    >
    > > Hopefully that gives you some ideas anyway.

    >
    > > Mike


    Oh. I thought you had compiled the program yourself. I suppose you
    could use SendKeys then. I have a couple links here:

    http://pythonlibrary.org/python/SendKeys

    It's pretty hackneyed, but I've used the SendKeys module to automate
    Firefox to some degree.

    Mike
    , Aug 7, 2007
    #4
    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. Wagner Dias
    Replies:
    3
    Views:
    3,052
    Andre Kostur
    Mar 28, 2005
  2. Larry Hastings
    Replies:
    0
    Views:
    268
    Larry Hastings
    Jul 20, 2006
  3. rcmn
    Replies:
    1
    Views:
    333
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Nov 6, 2006
  4. wukong

    subprocess only good for win32?

    wukong, Mar 31, 2010, in forum: Python
    Replies:
    9
    Views:
    690
    Piet van Oostrum
    Apr 1, 2010
  5. hiral
    Replies:
    2
    Views:
    598
    Jean-Michel Pichavant
    May 5, 2010
Loading...

Share This Page