Howto Launch a windows application ?

stef mientki stef.mientki at gmail.com
Fri Oct 5 14:51:18 EDT 2007


Nicholas Bastin wrote:
> On 10/3/07, stef mientki <stef.mientki at gmail.com> wrote:
>   
>> hello,
>>
>> I'm trying to launch a windows application,
>> but as many others on this list, I've some trouble.
>> I read some other threads about this topic,
>> but sorry, I still don't understand all this (never heard of pipes).
>>
>> When I use a batch file, I can launch the bat-file from python,
>> and the windows application launched from the batchfile is run perfectly.
>>
>> Now when I try to run the same windows application from Popen or call,
>> nothing happens (or at least it's very fast and produces not the
>> expected output).
>>
>> Please enlighten me, preferable in "windows-terminology"  ;-)
>>
>> thanks,
>> Stef Mientki
>>
>> from subprocess import *
>>
>> cmd =[]
>> cmd.append ( 'D:\\PIC-tools\\JALxxx\\jalv2_3.exe' )
>> cmd.append ( '-long-start' )
>> cmd.append ( '-d')
>> cmd.append ( '-clear' )
>> cmd.append ( '-sD:\\PIC-tools\\JAL\\libs2' )
>> cmd.append ( 'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal' )
>> cmd.append ( '>d:\\data_actueel\\d7_test_browser\\temp.log' )
>>
>> # DOESN'T WORK
>> result = call ( cmd )
>>
>> # Both Popen and call work
>> cmd = [ 'd:\\data_actueel\\d7_test_browser\\JALcc.bat' ]
>> #output = Popen ( cmd )
>> result = call ( cmd )
>> print result
>>     
>
> First, call is a convenience function, but in your case, it's probably
> not that convenient.  Use the actual Popen constructor so you can get
> at the output directly.  Also, ditch the output redirector and use a
> pipe:
>
> p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> (out, err) = p.stdout, p.stderr
> rcode = p.wait()
> print out, err, rcode
>
> Try that and see what happens.  When it doesn't work, look carefully
> in out and err and see if anything interesting is in there.  I was
> able to open notepad.exe in this way with no problems so my guess is
> you're having some other problem, but avoiding the use of the
> convenience function will give you stdout and stderr to look at.
>
>   
Thanks Nick,

replacing
    #print out, err, rcode
with
    for line in out:
          print line
    for line in err:
          print line
points me to the problem issue, which is the "-s" option,
although I don't understand it yet

> --
> Nick
>
>   




More information about the Python-list mailing list