所以我有一个python脚本生成一个networkx图并将其导出为.graphml,我希望脚本也能够在加载网络的情况下打开cytoscape而无需对用户部分进行任何操作。我明白了:
cytoscape.bat -N C:\Somepath\with\a\networkx.graphml
我使用它时工作正常。同样如下:
cd "C:\Program Files\Cytoscape_v3.0.0"
cytoscape.bat
但是,我似乎无法让os.system
或subprocess
正常运行,我目前的配置是:
p = subprocess.Popen("cytoscape.bat", cwd="C:/Program Files/Cytoscape_v3.0.0")
stdout, stderr = p.communicate()
但抛出了一个未找到文件的异常。
我一直在阅读有关运行.bats和执行cmd操作的其他stackoverflow帖子和python文档,并且可以使基础工作正常。然而,这似乎有点复杂,我不知道我哪里出错了!
根据要求我例外:
找不到文件和路径异常错误:
Traceback (most recent call last):
File "CytoScapeExporter.py", line 219, in <module>
p = subprocess.Popen("cytoscape.bat", cwd="\"C:/Program Files/Cytoscape_v3.0
.0\"")
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 267] The directory name is invalid
Traceback (most recent call last):
File "CytoScapeExporter.py", line 219, in <module>
p = subprocess.Popen("cytoscape.bat", cwd="C:/Program Files/Cytoscape_v3.0.0
")
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
稍有不同的JVM错误,它由以下代码生成:
os.system("\"C:/Program Files/Cytoscape_v3.0.0/cytoscape.bat\"")
Error: missing `server' JVM at `C:\Program Files (x86)\Java\jre7\bin\server\jvm.
dll'.
Please install or use the JRE or JDK that contains these missing components.
C:\Program Files\Cytoscape_v3.0.0
答案 0 :(得分:1)
“如果cwd不是None,则子节点的当前目录在执行之前将更改为cwd。请注意,在搜索可执行文件时不会考虑此目录,因此您无法指定程序的相对于CWD。强>“
您必须将命令的完整路径传递给subprocess.Popen。