我在Blender中有一个Python脚本,其中包含
subprocess.call(os.path.abspath('D:/Test/run-my-script.sh'),shell=True)
其后是许多依赖于此Shell脚本完成的其他代码。问题在于它没有等待脚本完成,我不知道为什么?我甚至尝试使用Popen
而不是call
,如下所示:
p1 = subprocess.Popen(os.path.abspath('D:/Test/run-my-script.sh'),shell=True)
p1.wait()
我尝试使用沟通,但仍然没有起作用:
p1 = subprocess.Popen(os.path.abspath('D:/Test/run-my-script.sh'),shell=True).communicate()
这个shell脚本在MacOS上运行良好(修改路径后)并且在使用subprocess.call(['sh', '/userA/Test/run-my-script.sh'])
时会等待。
但是在Windows上,当我在Blender中运行以下Python脚本时,一旦它到达子进程的那一行Git Bash
就会被打开并运行shell脚本,而Blender不会等待它完成,只是在控制台中打印出Hello
而已。有什么帮助吗?
Translated text:
This shell script runs well on MacOS (after modifying the paths) and waits when using subprocess.call(['sh', '/userA/Test/run-my-script.sh'])
.
However, on Windows, when I run the following Python script in Blender, once it reaches the subprocess line, Git Bash
is opened and the shell script runs. Blender does not wait for it to finish, but only prints Hello
in its console. Is there any help?
import bpy
import subprocess
subprocess.call(os.path.abspath('D:/Test/run-my-script.sh'),shell=True)
print('Hello')
D:/Test/run-my-script.sh
时会发生什么?它会立即返回吗? - AShelly