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

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?

Perhaps this thread will answer your question

Oh and P.S.; command = "OK" + os.linesep is a platform independent way to implement that...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.