473,386 Members | 1,621 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,386 software developers and data experts.

shell script stdout to python string?


Hi -- sorry for not searching first, but I get an NNTP error from
netscape (a known bug, still looking for workaround).

Inside a python script, I want to execute a UNIX command and
send the output to a Python string, returning the shell return
code value as an integer or exception.

I'm sure I could write a function using pipes and whatnot, but
I'm hoping this is a solved problem by now, more elegantly and
correctly coded than my hack job would be.

Thanks,
Jeff

Python rocks, btw. I've almost broken the #!/bin/ksh habit ;)

Jul 18 '05 #1
2 2321

Check out:

http://www.python.org/doc/current/li...-commands.html

It's Unix-specific, but I guess you did say "Unix command"...
-Rick Ratzel
Jeff Learman wrote:

Hi -- sorry for not searching first, but I get an NNTP error from
netscape (a known bug, still looking for workaround).

Inside a python script, I want to execute a UNIX command and
send the output to a Python string, returning the shell return
code value as an integer or exception.

I'm sure I could write a function using pipes and whatnot, but
I'm hoping this is a solved problem by now, more elegantly and
correctly coded than my hack job would be.

Thanks,
Jeff

Python rocks, btw. I've almost broken the #!/bin/ksh habit ;)

Jul 18 '05 #2
Thanks! Just what I was looking for ... don't know why I didn't
see it in the docs.

Rick L. Ratzel wrote:

Check out:

http://www.python.org/doc/current/li...-commands.html

It's Unix-specific, but I guess you did say "Unix command"...
-Rick Ratzel
Jeff Learman wrote:

Hi -- sorry for not searching first, but I get an NNTP error from
netscape (a known bug, still looking for workaround).

Inside a python script, I want to execute a UNIX command and
send the output to a Python string, returning the shell return
code value as an integer or exception.

I'm sure I could write a function using pipes and whatnot, but
I'm hoping this is a solved problem by now, more elegantly and
correctly coded than my hack job would be.

Thanks,
Jeff

Python rocks, btw. I've almost broken the #!/bin/ksh habit ;)


Jul 18 '05 #3

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

Similar topics

4
by: jelle | last post by:
Hi, I use python quite a bit to couple different programs together. Doing so has been a _lot_ easier since subprocess came around, but would really like to be able to use the succinct shell...
10
by: A.M | last post by:
Hi, I am having difficulty with shell scripting in Python. I use the following command to run a DOS command and put the return value in a Python variable:
2
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run....
3
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as...
3
by: koutoo | last post by:
Is it possible to display messages in the python shell? I want to display error messages based on parameters in my scripts to the users. Is there another way to display messages other than log...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
1
by: ellipsism | last post by:
Hello, I'm using VBA from Excel to call a python script with some arguments. The python script returns only true or false, which is the information I want to take back into Excel. I'm wondering,...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.