473,397 Members | 1,969 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.

How to get the output from os.system() into a variable?

Hi,

I would like to execute some command in python on the bash, e.g.

os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l
/bin/date')

and want the result of the output in a vector, so something like:

result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?

Thanks
Alexander Dietz

Oct 5 '05 #1
4 5285
"alexLIGO" <di***@rouge.phys.lsu.edu> writes:
I would like to execute some command in python on the bash, e.g.

os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l
/bin/date')

and want the result of the output in a vector, so something like:

result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?


Check out the commands module.

http://docs.python.org/lib/module-commands.html

--
Björn Lindström <bk**@stp.lingfil.uu.se>
Student of computational linguistics, Uppsala University, Sweden
Oct 5 '05 #2
alexLIGO wrote:
Hi,

I would like to execute some command in python on the bash, e.g.

os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l
/bin/date')

and want the result of the output in a vector, so something like:

result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?

You can use one of these:

the subprocess module: http://docs.python.org/lib/module-subprocess.html
the popen2 module: http://docs.python.org/lib/module-popen2.html
popen and spawn variants from the os module:
http://docs.python.org/lib/os-process.html
pexpect (it is not in the standard library):
http://pexpect.sourceforge.net/

I believe that if you do not need the extended functionality of
"pexpect", then you should start with the "subprocess" module.
It is the newest.

Les

Oct 5 '05 #3
result=python_command(' command_on_the_bash ')

Is that possible? And how to do that?


Check out the commands module.

http://docs.python.org/lib/module-commands.html

Hmm, I forgot this one. It is only working from UNIX, am I right?

Les

Oct 5 '05 #4
Hi,

thank you very much for your tipps. I get it to work!

Alexander

Oct 5 '05 #5

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

Similar topics

2
by: praba kar | last post by:
Dear all, I want to parse the system functions output but I couldn't do it. Kindly assist me in this task. eg) bytesused = os.system('du -sh /Users/enmail') if I print this bytesused...
3
by: Glen | last post by:
Hi, I just have a quick question Im trying to initialize a string (or char) variable with the information created by the output of a shell (or DOS) command.. Example: I want to execute a...
14
by: jas | last post by:
I would like to redirect the output from os.system to a variable, but am having trouble. I tried using os.popen(..).read() ...but that doesn't give me exactly what i want. ...this is windows by...
2
by: DC Gringo | last post by:
I would like to know how to set an output parameter to a variable and output it on a web form: This didn't work: Me.SqlSelectCommand1.Parameters.Add(New...
5
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is...
5
by: Muffin | last post by:
I am trying to capture the out put of a command line program. Let say ping or maybe better yet nslookup. I would like to launch and then capture all the output , redirect it I guess to a string...
0
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
1
by: rogerford | last post by:
Hi, I am trying to retrieve a value from database, based on that value I want to insert records into DB.Let’s say I am retrieving tsmid which serves as the output parameter in the stored procedure....
13
by: Jim Langston | last post by:
I had asked this in comp.lang.c++ with out any answers that would actually work, so I'm hoping someone here may know a way. I am calling C library functions that want to output to stdout. I need...
2
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.