title: How to call a Python script with arguments from Java class
body: <p>I am using <em>Python 3.4</em>.</p>
  
  <p>I have a Python script <code>myscript.py</code> :</p>
  
  <pre><code>import sys
  def returnvalue(str) :
      if str == "hi" :
          return "yes"
      else :
          return "no"
  print("calling python function with parameters:")
  print(sys.argv[1])
  str = sys.argv[1]
  res = returnvalue(str)
  target = open("file.txt", 'w')
  target.write(res)
  target.close()
  </code></pre>
  
  <p>I need to call this python script from the java class <code>PythonJava.java</code></p>
  
  <pre><code>public class PythonJava 
  {
      String arg1;
      public void setArg1(String arg1) {
          this.arg1 = arg1;
      }
  public void runPython() 
      { //need to call myscript.py and also pass arg1 as its arguments.
        //and also myscript.py path is in C:\Demo\myscript.py
  }
  </code></pre>
  
  <p>and I am calling <code>runPython()</code> from another Java class by creating an object of <code>PythonJava</code></p>
  
  <pre><code>obj.setArg1("hi");
  ...
  obj.runPython();
  </code></pre>
  
  <p>I have tried many ways but none of them are properly working. I used Jython and also ProcessBuilder but the script was not write into file.txt. Can you suggest a way to properly implement this?</p>