문제

So I have a python script that produces a networkx graph and exports it as .graphml and I want script to also be able to open cytoscape with the network loaded without any work on the users part. I understand:

cytoscape.bat -N C:\Somepath\with\a\networkx.graphml

and it works fine when I use it. As does:

cd "C:\Program Files\Cytoscape_v3.0.0"
cytoscape.bat

However, I can't seem to get either os.system or subprocess to run properly, my current configuration is:

p = subprocess.Popen("cytoscape.bat", cwd="C:/Program Files/Cytoscape_v3.0.0")
stdout, stderr = p.communicate()

But the throws a file-not-found-exception.

I've been reading up on other stackoverflow posts and python docs on running .bats and doing cmd operations, and can get the basics to work. However, this seems somewhat more complicated, and I'm not sure where I'm going wrong!

As requested I exceptions:

The file not found and incorrect path exceptions:

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

A slightly different JVM error, it is produced by this code:

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
도움이 되었습니까?

해결책

From the documentation:

"If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd."

You have to pass the full path of the command to subprocess.Popen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top