[英]subprocess, Popen to run command in a module
i want to call a binary program from within my module. 我想从我的模块中调用一个二进制程序。 i am having problem with subprocess finding the binary. 我在查找二进制文件的子过程中遇到问题。
so i have 所以我有
myModule/
-classWrappingBinary.py
-binary_file.out
and in classWrappingBinary.py i have somthing like 在classWrappingBinary.py中,我有类似的东西
sbp.Popen(['./binary_file.out']
which doesnt work. 这不起作用。 so how can i successfully call the Popen command? 所以我怎么能成功调用Popen命令呢? i am going to use it by importing the module like, 我将通过导入模块来使用它,
import myModule
a = myModule.classWrappingBinary.MyClass()
You can look at the variable __file__
and extract the directory information from it. 您可以查看变量__file__
并从中提取目录信息。 The most reliable way is 最可靠的方法是
name = os.path.join(os.path.dirname(__file__) or ".", "binary_file.out")
subprocess.Popen(name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.