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()
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>, Donn Cave <donn at
>>Quoth Damian Menscher <menscher+python at uiuc.edu>:
| I'm new to Python (as in, my experience is essentially the
>>| 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
>>| 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
>>| 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
| Ideas? I'm trying to avoid writing the string out to a file and
>>| 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
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()
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.

Oct 28 '07 #2

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

Similar topics

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...
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...
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 =...
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)
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...
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(.......); .....; )
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;
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 =...
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....
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=()=>{
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...
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...
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 :...
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...
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...
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...
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...
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.