process Builder java cannot run some of the python code in java. How to solve?
<p>I am using java to create ProcessBuilder to run python. </p>

<p>Both of the two py can be run sucessfully in the python program. (the two py have no issue with the code)</p>

<p>input.py:</p>

<pre><code>print 'hello'  
number=[3,5,2,0,6]  
print number  
number.sort()  
print number  
number.append(0)  
print number  
print number.count(0)  
print number.index(5)
</code></pre>

<p>TESTopenBaseOnt.py:</p>

<pre><code>from rdflib import URIRef, Graph, Namespace
from rdflib.plugins.parsers.notation3 import N3Parser
from rdflib.namespace import RDF, OWL, RDFS
from rdflib import URIRef, BNode, Literal
from rdflib import Namespace
from rdflib.namespace import RDF, FOAF, RDFS
from rdflib import Graph

gUpdate = Graph()
print ".&gt; Step....1"
gUpdate.parse("BBCOntology.rdf" )
print ".&gt; Step....2"
print gUpdate.serialize(format='xml')
print ".&gt;  Finished......."
#
</code></pre>

<p>AS you can see the picture. </p>

<p>The code works for python:input.py
However, it does not work for python:TESTopenBaseOnt.py<br>
It might be because java cannot run the parse function in python. as the result shows that, the program stoped at step1.</p>

<pre><code>public static void main(String [] args) throws IOException
    {

        try

        {
        ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","C:Desktop//searchTestJava//input.py");

//      ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","C:Desktop//searchTestJava//TESTopenBaseOnt.py");



        Process p = pb.start();
        BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));

        System.out.println(".........start   process.........");  
        String line = "";     
        while ((line = bfr.readLine()) != null){
            System.out.println("Python Output: " + line);
        }

        System.out.println("........end   process.......");


        }catch(Exception e){System.out.println(e);}


    }
</code></pre>

<p>So how to solve the problem that the python cannot run in the java
<a href="http://i.stack.imgur.com/L0r4Z.png" rel="nofollow"><img src="http://i.stack.imgur.com/L0r4Z.png" alt="enter image description here"></a></p>

<pre><code>gUpdate = Graph()
print ".&gt; Step....1"
gUpdate.parse("D:\\Desktop\\searchTestJava\\BBCOntology.rdf" )
print ".&gt; Step....2"       
</code></pre>

<p>The BBCOntology.rdf is  in the current working directory of the Python process. So the program can work in python even if I wrote as (gUpdate.parse("BBCOntology.rdf" )). </p>

<p>However, java does not know the directory BBCOntology.rdf is same as the TESTopenBaseOnt.py. 
Once I add the gUpdate.parse("D:\Desktop\searchTestJava\BBCOntology.rdf" ) , Java can work. </p>

java python parsing rdf processbuilder