A
Amanda Jamin
Subprocess issues with platform independence
Postby ajamin on Wed Oct 08, 2008 10:46 am
I am writing a python script that will act as a wrapper for another
program. The python script will provide the inputs for this program
and will verify that the output is correct. The application runs on
multiple OS's including windows and *nix.
This is the code:
Code: Select all
Help with Code Tags
python Syntax (Toggle Plain Text)
1.
import os, sys, string, time, subprocess
2.
command = "OK\r\n"
3.
p = subprocess.Popen( ("C:\setup-winnt.exe", "-console"),
4.
stdin = subprocess.PIPE,
5.
stdout = subprocess.PIPE,
6.
stderr = subprocess.PIPE)
7.
stdout_text, stderr_text = p.communicate(command)
8.
sys.stdout.writelines(stdout_text.rstrip())
import os, sys, string, time, subprocess command = "OK\r\n" p =
subprocess.Popen( ("C:\setup-winnt.exe", "-console"), stdin =
subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
stdout_text, stderr_text = p.communicate(command)
sys.stdout.writelines(stdout_text.rstrip())
On the *nix version, the application to open ("C:\setup-winnt.exe")
and the command ("OK\r\n") are different. The plan is to refactor this
as the code develops.
The above code works fine on *nix. On these OS's the application
launches in the same console that the command is issued from. On
windows the behavior is different. When the command is executed an
initialization window opens. When this window closes, a command window
is opened. It is this command window that I wish to send commands to.
I believe this command window may be started as a child process of the
application. However it is opened, it does not accept input from the
stdin of the process.
Any suggestions?
Postby ajamin on Wed Oct 08, 2008 10:46 am
I am writing a python script that will act as a wrapper for another
program. The python script will provide the inputs for this program
and will verify that the output is correct. The application runs on
multiple OS's including windows and *nix.
This is the code:
Code: Select all
Help with Code Tags
python Syntax (Toggle Plain Text)
1.
import os, sys, string, time, subprocess
2.
command = "OK\r\n"
3.
p = subprocess.Popen( ("C:\setup-winnt.exe", "-console"),
4.
stdin = subprocess.PIPE,
5.
stdout = subprocess.PIPE,
6.
stderr = subprocess.PIPE)
7.
stdout_text, stderr_text = p.communicate(command)
8.
sys.stdout.writelines(stdout_text.rstrip())
import os, sys, string, time, subprocess command = "OK\r\n" p =
subprocess.Popen( ("C:\setup-winnt.exe", "-console"), stdin =
subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
stdout_text, stderr_text = p.communicate(command)
sys.stdout.writelines(stdout_text.rstrip())
On the *nix version, the application to open ("C:\setup-winnt.exe")
and the command ("OK\r\n") are different. The plan is to refactor this
as the code develops.
The above code works fine on *nix. On these OS's the application
launches in the same console that the command is issued from. On
windows the behavior is different. When the command is executed an
initialization window opens. When this window closes, a command window
is opened. It is this command window that I wish to send commands to.
I believe this command window may be started as a child process of the
application. However it is opened, it does not accept input from the
stdin of the process.
Any suggestions?