Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 2nd, 2006, 09:15 PM
Kkaa
Guest
 
Posts: n/a
Default Hiding Console Output

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?

  #2  
Old August 2nd, 2006, 10:55 PM
Larry Bates
Guest
 
Posts: n/a
Default Re: Hiding Console Output

Kkaa wrote:
Quote:
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
  #3  
Old August 3rd, 2006, 12:45 AM
kyle.tk
Guest
 
Posts: n/a
Default Re: Hiding Console Output


Kkaa wrote:
Quote:
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

  #4  
Old August 3rd, 2006, 01:25 AM
placid
Guest
 
Posts: n/a
Default Re: Hiding Console Output


Kkaa wrote:
Quote:
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/

  #5  
Old August 3rd, 2006, 03:45 PM
Kkaa
Guest
 
Posts: n/a
Default Re: Hiding Console Output

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=subproc ess.PIPE,stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
sts = os.waitpid(p.pid, 0)

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

placid wrote:
Quote:
Kkaa wrote:
Quote:
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/
  #6  
Old August 3rd, 2006, 06:35 PM
Simon Forman
Guest
 
Posts: n/a
Default Re: Hiding Console Output

Kkaa wrote:
Quote:
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=subproc ess.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

  #7  
Old August 5th, 2006, 06:15 AM
John Savage
Guest
 
Posts: n/a
Default Re: Hiding Console Output

"Kkaa" <onlyafly@gmail.comwrites:
Quote:
>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?
Quote:
>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.
--
John Savage (my news address is not valid for email)
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles