471,355 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Howto Launch a windows application ?

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.ja l' )
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

Oct 3 '07 #1
5 1896

stef mientki 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.ja l' )
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

Oct 3 '07 #2
stef mientki wrote:
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.ja l' )
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.ja l
>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.
Oct 3 '07 #3
Yu-Xi Lim wrote:
stef mientki wrote:
>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.ja l' )
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
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.ja l
>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.
Oct 4 '07 #4
Matimus wrote:
stef mientki 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.ja l' )
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
Matt

Oct 4 '07 #5
On Oct 3, 5:39 pm, stef mientki <stef.mien...@gmail.comwrote:
>
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.ja l' )
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.ja l',
'>d:\\data_actueel\\d7_test_browser\\temp.log']

Hyuga

Oct 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Paul | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.