FAQ
This question has me running around in circles. I am running a Python
process that needs to execute a DOS executable and return a value based on
success or failure. I need to continue the Python process after this has
completed. It seems to me that I should be able to execute and return, but
the commands I've read so far don't give me much hope. Here's what I've
found:

- os.system could execute, but the return is whether or not Python
executed the command, not whether the command completed successfully.

- os.execv would execute, but it would kill the Python process and
replace it with the executable, while I need to continue the Python process.

- spawn would work, except I'm not in Windows, I'm in DOS.

If there is any input to this question, I would greatly appreciate it. I
can provide more information, if only I knew what would help.

- Mark

----------------------------------------------------------------------------
----------------
The opinions expressed are mine, and not necessarily those of my employer.

Search Discussions

  • Tom at Sep 20, 2000 at 3:45 pm
    All I can add is that the API call you need is CreateProcess(). But I don't
    know what Python function would use this API.

    Tom.

    "Daley, Mark W" <mark.w.daley at intel.com> wrote in message
    news:75F7304BB41CD411B06600A0C98414FCB36910 at ORSMSX54...
    This question has me running around in circles. I am running a Python
    process that needs to execute a DOS executable and return a value based on
    success or failure. I need to continue the Python process after this has
    completed. It seems to me that I should be able to execute and return, but
    the commands I've read so far don't give me much hope. Here's what I've
    found:

    - os.system could execute, but the return is whether or not Python
    executed the command, not whether the command completed successfully.

    - os.execv would execute, but it would kill the Python process and
    replace it with the executable, while I need to continue the Python process.
    - spawn would work, except I'm not in Windows, I'm in DOS.

    If there is any input to this question, I would greatly appreciate it. I
    can provide more information, if only I knew what would help.

    - Mark

    -------------------------------------------------------------------------- --
    ----------------
    The opinions expressed are mine, and not necessarily those of my employer.

  • Fredrik Lundh at Sep 20, 2000 at 3:50 pm

    Mark wrote:
    - spawn would work, except I'm not in Windows, I'm in DOS.
    is that "DOS" as in "MS-DOS 6", or "DOS" as in "an MS-DOS
    prompt (or a console window) running under Windows" ?

    if the former, what Python version/build are you using?

    </F>
  • Daley, Mark W at Sep 20, 2000 at 4:43 pm
    What I'm using is an Extensible Firmware Interface that acts like MS-DOS.
    Most MS-DOS commands work the same under EFI. We are using Python 1.5.2.
    We have a local build that doesn't contain all of the functions in the
    standard distribution.

    -----Original Message-----
    From: Fredrik Lundh [mailto:effbot at telia.com]
    Sent: Wednesday, September 20, 2000 8:50 AM
    To: python-list at python.org
    Subject: Re: Executing files


    Mark wrote:
    - spawn would work, except I'm not in Windows, I'm in DOS.
    is that "DOS" as in "MS-DOS 6", or "DOS" as in "an MS-DOS
    prompt (or a console window) running under Windows" ?

    if the former, what Python version/build are you using?

    </F>
  • Tim Peters at Sep 20, 2000 at 10:27 pm
    [Mark W Daley, running a customized Python on something "like" DOS]
    ...
    - os.system could execute, but the return is whether or not
    Python executed the command, not whether the command completed
    successfully.
    Since you've customized Python and aren't actually running DOS, it's risky
    to guess, but here goes:

    On a non-customized Python running on real DOS, os.system always returns 0
    whenever the argument passed to it runs at all. That's because command.com
    ignores the exit status of commands *it* runs, returning 0 as its own exit
    status: Microsoft's implementation of "system" (which Python calls
    directly) builds a command line out of %COMSPEC% and the argument to
    "system", like so:

    %COMSPEC% /c argument_to_system

    then spawns a process to run that (note that the source code for Microsoft's
    "system" is available in crt\src\system.c, provided you elected to install
    the C runtime source when you installed MSVC). Since command.com always
    returns 0, that's what Microsoft's system returns to Python's os.system
    returns to you.

    To fix this, you need a better shell, and point the COMSPEC envar at it.
    IIRC, those running NT don't have this problem, because the std shell there
    (cmd.exe) does return the exit status of the command it runs.

    who-says-ms-isn't-open-source<wink>?-ly y'rs - tim
  • Cameron Laird at Sep 21, 2000 at 1:51 pm
    In article <LNBBLJKPBEHFEDALKOLCOECIHHAA.tim_one at email.msn.com>,
    Tim Peters wrote:
    [Mark W Daley, running a customized Python on something "like" DOS]
    ...
    - os.system could execute, but the return is whether or not
    Python executed the command, not whether the command completed
    successfully.
    Since you've customized Python and aren't actually running DOS, it's risky
    to guess, but here goes:

    On a non-customized Python running on real DOS, os.system always returns 0
    whenever the argument passed to it runs at all. That's because command.com
    ignores the exit status of commands *it* runs, returning 0 as its own exit
    status: Microsoft's implementation of "system" (which Python calls
    directly) builds a command line out of %COMSPEC% and the argument to
    "system", like so:

    %COMSPEC% /c argument_to_system

    then spawns a process to run that (note that the source code for Microsoft's
    "system" is available in crt\src\system.c, provided you elected to install
    the C runtime source when you installed MSVC). Since command.com always
    returns 0, that's what Microsoft's system returns to Python's os.system
    returns to you.

    To fix this, you need a better shell, and point the COMSPEC envar at it.
    IIRC, those running NT don't have this problem, because the std shell there
    (cmd.exe) does return the exit status of the command it runs.
    .
    .
    .
    Tim, it's also possible to hack an extension to
    his 1.5.2 that runs DOS commands directly. That
    is, while I haven't done this with 1.5.2, it's
    the kind of thing I used to do with other DOS
    applications, and the Python source is plenty
    clean enough to make this alternative inviting.

    ... IF he is in a position to change his Python
    language processor. The original question doesn't
    make that clear to me.
    --

    Cameron Laird <claird at NeoSoft.com>
    Business: http://www.Phaseit.net
    Personal: http://starbase.neosoft.com/~claird/home.html
  • Jay Krell at Sep 22, 2000 at 5:54 am

    What I'm using is an Extensible Firmware Interface that acts like MS-DOS.
    Most MS-DOS commands work the same under EFI. We are using Python 1.5.2.
    We have a local build that doesn't contain all of the functions in the
    standard distribution.
    Huh?! EFI is NOT DOS. EFI is yet another runtime environment that happens to
    usually have a command line for an interface, but there are non command line
    apps for it, like a full screen editor.

    EFI IS NOT DOS.
    EFI is not Unix. EFI is not Windows. EFI is EFI.
    I don't think EFI has a notion of processes, but you can load files and jump
    into them.

    "command line" != "DOS"
    Windows NT cmd.exe is not DOS.
    Windows 9x console, maybe it is somewhat DOS, I don't know.

    - Jay

    -----Original Message-----
    From: Daley, Mark W <mark.w.daley at intel.com>
    To: python-list at python.org <python-list at python.org>
    Date: Wednesday, September 20, 2000 9:47 AM
    Subject: RE: Executing files

    What I'm using is an Extensible Firmware Interface that acts like MS-DOS.
    Most MS-DOS commands work the same under EFI. We are using Python 1.5.2.
    We have a local build that doesn't contain all of the functions in the
    standard distribution.

    -----Original Message-----
    From: Fredrik Lundh [mailto:effbot at telia.com]
    Sent: Wednesday, September 20, 2000 8:50 AM
    To: python-list at python.org
    Subject: Re: Executing files


    Mark wrote:
    - spawn would work, except I'm not in Windows, I'm in DOS.
    is that "DOS" as in "MS-DOS 6", or "DOS" as in "an MS-DOS
    prompt (or a console window) running under Windows" ?

    if the former, what Python version/build are you using?

    </F>


    --
    http://www.python.org/mailman/listinfo/python-list

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 20, '00 at 3:35p
activeSep 22, '00 at 5:54a
posts7
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase