Howto Launch a windows application ?

S

stef mientki

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
 
M

Matimus

stef said:
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

My guess is that with the redirect you simple need to set the 'shell'
option to true.

call(cmd, shell=True)

I haven't tested it, but it is worth a try.

Matt
 
Y

Yu-Xi Lim

stef said:
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' )

Your problem is probably the last line there with the '>'. That's an
output redirection that is done not by jalv2_3.exe but by the command
shell. That's why it works only with the batch file (which is
interpreted by the command shell.

Using a batch file is probably easiest for this. But I'm guessing you
probably want to change the command line arguments passed to the program
that's why you prefer to build the command line manually.

In that case, there are a few solutions:
1) Generate the batch file programmatically.
2) Use cmd.exe /C (assuming you're on Windows XP). So your program would
be something like:
cmd.append('cmd.exe')
cmd.append('/C')
cmd.append('"D:\\PIC-tools\\JALxxx\\jalv2_3.exe -long-start -d -clear
-sD:\\PIC-tools\\JAL\\libs2
d:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal
>d:\\data_actueel\\d7_test_browser\\temp.log"')
(or something like that)
3) Do the redirection yourself. Remove the line:
cmd.append ('>d:\\data_actueel\\d7_test_browser\\temp.log' )
and instead read the results directly from the Popen.stdout. You can
then write the output to a file if you want.
 
S

stef mientki

Yu-Xi Lim said:
stef said:
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' )

Your problem is probably the last line there with the '>'. That's an
output redirection that is done not by jalv2_3.exe but by the command
shell. That's why it works only with the batch file (which is
interpreted by the command shell.
No that's not the problem,
leaving the redirection away,
gives the same problems.
Using a batch file is probably easiest for this.
I think indeed that's he simplest solution.
Still wonder why launching a windows program is "so difficult" in python
;-)

thanks,
Stef Mientki
 
S

stef mientki

Matimus said:
stef said:
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

My guess is that with the redirect you simple need to set the 'shell'
option to true.

call(cmd, shell=True)

I haven't tested it, but it is worth a try.
thanks, I tried, but it didn't work.

cheers,
Stef
 
H

Hyuga

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' )

This is sort of aside from your original question, but I should also
point out how unnecessary all those 'cmd.append's are. You can
initialize the list all at once simply like so:

cmd =['D:\\PIC-tools\\JALxxx\\jalv2_3.exe',
'-long-start',
'-d',
'-clear',
'-sD:\\PIC-tools\\JAL\\libs2',
'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal',
'>d:\\data_actueel\\d7_test_browser\\temp.log']

Hyuga
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top