472,958 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 9506
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
13
by: vashwath | last post by:
Hi all, To test the return value of system I wrote 2 programs which are shown below. Program 1: #include <stdio.h> #include <stdlib.h> int main(void)
7
by: Rudy | last post by:
Hello All! I have a value in a textbox(txbTableIDm.Text ) that I would like to use in a paremiter in a SP I wrote, and then have the select statement work off that parememter, retireive a...
2
by: murat.migdisoglu | last post by:
hi, while i was browsing some codes, i've seen multiple times casting the return value of memcpy function to void. ( ......; ......; (void)memcpy(.......); .....; )
4
by: arnuld | last post by:
1.) we usually say /return 0/ indicates success e.g #include <iostream> int main() { int i=3; std::cout << i << std::endl; return 0;
4
by: Mick Walker | last post by:
Hi Everyone, I am stumped here. I have the following stored proceedure:P CREATE PROCEDURE . @SupplierSKU varchar(50), @RetVal int AS Select @Retval = count(*) from dbo.ImportLines Where =...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.