📝 Update comments and document OS-specific subprocess handling in test script
This commit is contained in:
+11
-2
@@ -17,6 +17,7 @@ if __name__ == "__main__":
|
|||||||
result.check_returncode()
|
result.check_returncode()
|
||||||
print('return code:', result.returncode)
|
print('return code:', result.returncode)
|
||||||
print(result.stdout)
|
print(result.stdout)
|
||||||
|
|
||||||
print("*" * 100)
|
print("*" * 100)
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['env'],
|
['env'],
|
||||||
@@ -40,7 +41,7 @@ if __name__ == "__main__":
|
|||||||
subprocess.run(
|
subprocess.run(
|
||||||
['sleep', '5'],
|
['sleep', '5'],
|
||||||
env=my_env,
|
env=my_env,
|
||||||
check=True, # 非 0 返回时抛出异常
|
check=True, # 非 0 返回时抛出异常,相当于 result.check_returncode()
|
||||||
)
|
)
|
||||||
|
|
||||||
print("*" * 100)
|
print("*" * 100)
|
||||||
@@ -48,7 +49,15 @@ if __name__ == "__main__":
|
|||||||
['sleep', '50'],
|
['sleep', '50'],
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=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)
|
print("*" * 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user