📝 Update comments and document OS-specific subprocess handling in test script

This commit is contained in:
2026-05-24 00:02:58 +08:00
parent 97aa505ac2
commit efcdf6e2d7
+11 -2
View File
@@ -17,6 +17,7 @@ if __name__ == "__main__":
result.check_returncode()
print('return code:', result.returncode)
print(result.stdout)
print("*" * 100)
result = subprocess.run(
['env'],
@@ -40,7 +41,7 @@ if __name__ == "__main__":
subprocess.run(
['sleep', '5'],
env=my_env,
check=True, # 非 0 返回时抛出异常
check=True, # 非 0 返回时抛出异常,相当于 result.check_returncode()
)
print("*" * 100)
@@ -48,7 +49,15 @@ if __name__ == "__main__":
['sleep', '50'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
preexec_fn=os.setpgrp # 让子进程独立,即使当前脚本挂了它也继续运行
preexec_fn=os.setpgrp # 让子进程独立,即使当前脚本挂了它也继续运行 for Linux/Unix/MacOS
)
# for Windows
# flags = 0x00000008 | 0x00000200
# process = subprocess.Popen(
# ["cmd", "/c", "your_script.bat"],
# stdout=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL,
# creationflags=flags
# )
print("*" * 100)