Skip to content

os.execvp on windows doesn't wait for the executed program to finish and doesn't report it's exit code #101191

Open
@snoopyjc

Description

@snoopyjc

Bug report

os.execvp on windows doesn't wait for the executed program to finish and doesn't report it's exit code. Code:

import os
import sys

if len(sys.argv) > 1 and sys.argv[1] == "my_argument":
    sys.stderr.write("my_argument detected. Exiting with code 1.\n")
    sys.exit(1)
else:
    sys.stderr.write("no argument detected. Calling os.execvp\n")
    os.execvp(sys.executable, [sys.executable] + sys.argv + ["my_argument"])

bat file:

@echo off
python exec.py
if %errorlevel% NEQ 0 (
    echo The script gave exit code %errorlevel%
) else (
    echo Error: The script exited with exit code 0
)

Output from command prompt:

C:\pythonizer\play>exec.bat
no argument detected. Calling os.execvp
Error: The script exited with exit code 0

C:\pythonizer\play>my_argument detected. Exiting with code 1.

Note the command prompt prompted me for a new command before the exec'd process wrote out it's message.

Your environment

  • CPython versions tested on: 3.10.6
  • Operating system and architecture: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions