473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

os.system and command output

A.M
Hi,

How can I run an OS command and have the command's output (to stdout) in my
string variable?

For example in windows, this command should return a list of files within
directory:

os.system("DIR")

I am looking for an alternative function that returns the DIR command output
in a string

Thanks,

Alan
Jun 7 '06 #1
3 9995
A.M wrote:
Hi,

How can I run an OS command and have the command's output (to stdout) in my
string variable?

For example in windows, this command should return a list of files within
directory:

os.system("DIR")

I am looking for an alternative function that returns the DIR command output
in a string

Try:

s = os.popen("DIR").read()

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 7 '06 #2
A.M
Try:

s = os.popen("DIR").read()

Thanks Steve.

Is there anyway I can get the exit code (what os.system returns) from
os.popen?
Jun 7 '06 #3
A.M wrote:
Is there anyway I can get the exit code (what os.system returns) from
os.popen?


you'd rather kill yourself than read the documentation, right?

http://www.python.org/doc/lib/os-new...#os-newstreams

"The exit status of the command (encoded in the format specified
for wait()) is available as the return value of the close() method
of the file object, except that when the exit status is zero
(termination without errors), None is returned."

</F>

Jun 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: NewYorker | last post by:
Hi, I'm looking for code to do the following. Bascially, "System" shell out and execute the command and return the stdout in result. You know a link OR know the trick, please let me know. ...
6
by: jsw_nz | last post by:
Helo, my first post here.... I am trying to run an agent application that converts and imports two tables from MS Access into mySql. (Intelligent Converters - Access2mySql) I have run similar...
5
by: peter.pan | last post by:
Can someone give me a help? A need to create a program, that will simulate imput and output from command line. For example, I write in program dir "c:\program files\" and in the screen appear: ...
1
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. ...
1
by: hsmcdonald | last post by:
Hello all, I have a mail function that sends parsed information to an employee distribution list. I was trying to setup a process where the admin can initiate a letter to this list, and...
6
by: niskin | last post by:
I am running a system command and I need to capture the output so that, if the command has done what it is meant to, the program does something different. If I do this: int i; i=system("cd...
4
by: idorjee | last post by:
Hi, can anyone plz help me. I'm trying to run the 'pepwindow' program on the input from my html form, and my script doesn't work. The following '-goutfile' option in the system command is for the...
8
by: jkeith07 | last post by:
Ok so ive reached the end of my knowledge and have tried to find out how to do it and just plain dont understand it. I have a system call: system("db2cmd.exe \"db2 connect to vop9 user...
0
by: littlemaster | last post by:
scenario: --------- Need to upload the gpg encrypted file. Get that file and do decryption and store the output in a file Then extract that file and get the actual output Problem:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.