Subprocess problem on multiple OS's


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)

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)

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)

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?


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