471,350 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Return value from os.system() call

I was searching for ways to get the return value from os.system()
calls, when I came across this from 6 years ago. I tried what was
suggested in this thread, but
output = os.popen("/tmp/other").read()
returns
sh: line 1: /tmp/other: Permission denied

I'm relatively new to Python, hardly ever use the shell and am
currently running Python 2.5.5 on Mac OS 10.4.10

Cameron Laird <claird at starbase.neosoft.comwrote:
In article <98795o$kq8$0 at 216.39.151.169>, Donn Cave <donn at
oz.netwrote:
>>Quoth Damian Menscher <menscher+python at uiuc.edu>:
| I'm new to Python (as in, my experience is essentially the
tutorial),
>>| but I've already come up with an interesting question:
|
| How do I get the return code from an os.system call? I would have
| expected I could do something like
|
| ---returncode---
| #/bin/csh
| echo do stuff
| exit 3
|
| and then in my python program I could do
|
| print os.system('./returncode')
|
| But it prints out 768. Not particularly useful, even after I
recognize
>>| the trick of dividing by 256 (byte-swapping going on? No,
because a
>>| return code of 768 reports as 0). Given that my real return codes
| will be (possibly large) integers, this limitation will likely
cause
>>| some serious problems down the line.
|
| Even better would be a way of returning a string (the script I run
| can be something other than csh, but it has to be a separate
script).
>>|
| Ideas? I'm trying to avoid writing the string out to a file and
then
>>| read the file back in to the python program....
Guys, guys; you are making it too hard on Mr. Menscher. My guess
is that he'd appreciate being told that, if he creates /tmp/other
with contents
#!/bin/sh
echo "This is a string from an external process."
he can then have fun with
import os
print os.popen("/tmp/other").read()
Thank you much -- this solves my problem. I'm sure I'll have more
questions in the near future, though....

Damian Menscher
Oct 28 '07 #1
1 9273
Calder Coalson wrote:
I was searching for ways to get the return value from os.system() calls,
when I came across this from 6 years ago. I tried what was suggested in
this thread, but
output = os.popen("/tmp/other").read()
returns
sh: line 1: /tmp/other: Permission denied
I would assume that this is an OS problem more than a python problem. Do
you have write access to /tmp/other?
I'm fairly sure its a permission thing.

/W
Oct 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by siaj | last post: by
13 posts views Thread by vashwath | last post: by
7 posts views Thread by Rudy | last post: by
2 posts views Thread by murat.migdisoglu | last post: by
4 posts views Thread by arnuld | last post: by
4 posts views Thread by Mick Walker | last post: by
173 posts views Thread by Marty James | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.