python / python/cpython

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

未關閉
#101,191 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

OS-windows type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,使用提供的 Python 指令碼和批次檔重現 Windows 10 的行為,然後追蹤 os.execvp 進入點及其 Windows 實作。完成的標準是:執行的程式在批次檔繼續執行之前結束,且其非零結束碼會回報給呼叫端。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。