Search the web
Sign In
New User? Sign Up
a-a-p-dev · A-A-P project development list (closed)
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Question: getting the exit value of a shell command   Message List  
Reply | Forward Message #40 of 43 |
Re: [a-a-p-dev] Question: getting the exit value of a shell command


Aschwin Marsman wrote:

> > It looks like os.spawn*() only executes one command, not a shell command
> > or pipeline like "cat file | sed expr > tt".
>
> A shell command or pipeline is operating system specific also, if it can't
> be done with Python alone, you always have multi platform support problems.

Yep. Since A-A-P needs to execute compilers, linkers and other
programs, this is unavoidable. Python doesn't offer
platform-independent functions for everything either, quite a few things
are "Unix only" or "Windows only". I'm adding functions for this now
and then. I might even consider contributing some code to the Python
libraries.

To make it easy for the user to write a portable recipe, the plan is to
detect what tools are present on the system and provide a uniform
interface to it. The actions are used for this. For example, to
compile a C file into an object:

:do compile foo.c

The compile action can be defined explicitly:

:action compile object c
:sys $CC $CPPFLAGS $CFLAGS -c $source

But most of the actions will defined by default. See the "default.aap"
recipe in the distribution. The current list is only to try out the
mechanism, it has to be expanded considerably later. One item that
should be complete now is viewing a html page:

# Use the $BROWSER environment variable, a proposed standard; colon separated
# alternatives. If not set, search for one of the known browsers.
BROWSER = `os.environ.get('BROWSER')`
:action view html,xml,php
@if not BROWSER:
:progsearch BROWSER netscape mozilla konquerer grail iexplore mosaic
lynx w3m
:export BROWSER
:syspath '$BROWSER' $source

> What are the OS-es that need to be supported?

Unix (all kinds), MS-Windows (95 and later) and MacOS.

Unix is what I'm working on now. MS-Windows won't be too difficult to
add later. MacOS is going to be a challenge!

--
hundred-and-one symptoms of being an internet addict:
250. You've given up the search for the "perfect woman" and instead,
sit in front of the PC until you're just too tired to care.

/// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
/// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
\\\ Project leader for A-A-P -- http://www.a-a-p.org ///
\\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///



Tue Aug 20, 2002 8:28 am

vimboss
Offline Offline
Send Email Send Email

Forward
Message #40 of 43 |
Expand Messages Author Sort by Date

I ran into this issue and can't find a good solution. I hope someone knows the answer to this one. When executing a shell command with ":system", the exit...
Bram Moolenaar
vimboss
Offline Send Email
Aug 19, 2002
10:06 am

... Check google groups (groups.google.com). All solutions there read something like this: { the-command; } 2>&1 ; echo $? > res.tmp | tee /tmp/@... and then...
dionn@...
Send Email
Aug 19, 2002
11:05 am

... Thanks, that was exactly what I needed. The {} need to be placed differently though: { the-command; echo $? > res.tmp; } 2>&1 | tee /tmp/@... -- ...
Bram Moolenaar
vimboss
Offline Send Email
Aug 19, 2002
1:40 pm

... I've only a pointer for you. Hopefully someone will have a better answer, but you should be able to make some creative use of the $? special parameter? ...
Doug Kearns
djkea2@...
Send Email
Aug 19, 2002
11:13 am

Hi Doug, Bram, ... The 2>&1 and $? are only available at WinNT4/2K/XP, Win9x/Me doesnt offer them. The only alernative I know, is using CreateProcess() and...
Thorsten Maerz
torte@...
Send Email
Aug 19, 2002
11:33 am

... The Python documenation says os.system() doesn't return an exit value at all for MS-Windows 9x. It looks like spawn*() doesn't do the needed things...
Bram Moolenaar
vimboss
Offline Send Email
Aug 19, 2002
1:40 pm

... os.spawn*() works fine so long as you pass os.P_WAIT as the first argument, to wait for the exit status of the command. --SK...
Steven Knight
knight@...
Send Email
Aug 19, 2002
2:31 pm

... It looks like os.spawn*() only executes one command, not a shell command or pipeline like "cat file | sed expr > tt". -- If you're sending someone...
Bram Moolenaar
vimboss
Offline Send Email
Aug 19, 2002
6:15 pm

... A shell command or pipeline is operating system specific also, if it can't be done with Python alone, you always have multi platform support problems. What...
Aschwin Marsman - aYn...
marvinmarsman
Offline Send Email
Aug 19, 2002
6:57 pm

... Yep. Since A-A-P needs to execute compilers, linkers and other programs, this is unavoidable. Python doesn't offer platform-independent functions for...
Bram Moolenaar
vimboss
Offline Send Email
Aug 20, 2002
8:29 am

Hi Bram-- ... Here's a solution, from Tom Christiansen's classic "Csh Programming Considered Harmful" article: Consider the pipeline: A | B | C You want to...
Steven Knight
knight@...
Send Email
Aug 19, 2002
12:02 pm

... [...] ... Yes, this currently only works on Unix anyway. I noticed that os.system() always uses "sh", even though "tcsh" is my default shell. That's...
Bram Moolenaar
vimboss
Offline Send Email
Aug 19, 2002
1:41 pm

... You'll need to manipulate file descriptors, either directly using os.dup()/os.fdopen() or through library methods like popen2()/popen3(). In fact, take a...
Steven Knight
knight@...
Send Email
Aug 19, 2002
2:24 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help