Hiding Console Output

K

Kkaa

I'm using the os.system command in a python script on Windows to run a
batch file like this:

os.system('x.exe')

The third-party program x.exe outputs some text to the console that I
want to prevent from being displayed. Is there a way to prevent the
output of x.exe from python?
 
L

Larry Bates

Kkaa said:
I'm using the os.system command in a python script on Windows to run a
batch file like this:

os.system('x.exe')

The third-party program x.exe outputs some text to the console that I
want to prevent from being displayed. Is there a way to prevent the
output of x.exe from python?
Check out the subprocess module. With it you can control more than
with os.system().

-Larry
 
K

kyle.tk

Kkaa said:
I'm using the os.system command in a python script on Windows to run a
batch file like this:

os.system('x.exe')

The third-party program x.exe outputs some text to the console that I
want to prevent from being displayed. Is there a way to prevent the
output of x.exe from python?

Use os.popen('x.exe') instead.

-kyle
 
P

placid

Kkaa said:
I'm using the os.system command in a python script on Windows to run a
batch file like this:

os.system('x.exe')

The third-party program x.exe outputs some text to the console that I
want to prevent from being displayed. Is there a way to prevent the
output of x.exe from python?

using the subprocess module to create a subprocess and piping the
stdout,stdin and stderr so you wont see any ouput from the process
unless you read from the PIPE's.


import subprocess
p = subprocess.Popen("x.exe", shell=True,
stdout=subprocess.PIPE,stdin=subprocess.PIPE, stderr=subprocess.PIPE)



Cheers

-
http://bulkan.googlepages.com/python/
 
K

Kkaa

This seems like the right thing to do, but it runs the program in the
background, and I need my program to wait until the x.exe has finished.
I tried using this code:

p =
subprocess.Popen("x.exe",shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
sts = os.waitpid(p.pid, 0)

But I get the error: "No child process". Any ideas?
 
S

Simon Forman

Kkaa said:
This seems like the right thing to do, but it runs the program in the
background, and I need my program to wait until the x.exe has finished.
I tried using this code:

p =
subprocess.Popen("x.exe",shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
sts = os.waitpid(p.pid, 0)

But I get the error: "No child process". Any ideas?

Read the docs.

Here's a link to the docs for the subprocess.Popen object. Note the
second method? http://docs.python.org/lib/node239.html
 
J

John Savage

Kkaa said:
I'm using the os.system command in a python script on Windows to run a
batch file like this:

os.system('x.exe')

Is .exe really a batch file?
The third-party program x.exe outputs some text to the console that I
want to prevent from being displayed. Is there a way to prevent the
output of x.exe from python?

To consign stdout to nul in MSDOS you can use os.system('x.exe>nul')
so that will probably work for windows, too. This works regardless
of x.exe or x.bat so should do for whatever type of prog you are wanting
it for.
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top