title: call python script function from scala
body: <p>Attempt to call python function from scala fails with below error. But works fine when the same command is invoked directly from command line.</p>
  
  <p>Please find below simplified code snippets :-</p>
  
  <p><strong>greeting.py</strong></p>
  
  <pre><code>import logging
  import os
  
  
  def greet(arg):
      print("hey " + arg)
  </code></pre>
  
  <p><strong>StraightPyCall.scala</strong></p>
  
  <pre><code>package git_log
  
  object StraightPyCall {
  
    def main(args: Array[String]): Unit = {
  
      val commandWithNewLineInBeginning =
        """
          |python -c "import sys;sys.path.append('~/playground/octagon/bucket/pythonCheck'); from greeting import *; greet('John')"
          |""".stripMargin
  
      //new line stripped out from beginning and end
      val executableCommand = commandWithNewLineInBeginning.substring(1, commandWithNewLineInBeginning.length - 1)
  
      println("command is :-")
      println(executableCommand)
  
      import sys.process._
  
      s"$executableCommand".!!
    }
  }
  </code></pre>
  
  <p>output of above scala program is :-</p>
  
  <pre><code>command is :-
  python -c "import sys;sys.path.append('~/playground/octagon/bucket/pythonCheck'); from greeting import *; greet('John')"
  
    File "&lt;string&gt;", line 1
      "import
            ^
  SyntaxError: EOL while scanning string literal
  Exception in thread "main" java.lang.RuntimeException: Nonzero exit value: 1
      at scala.sys.package$.error(package.scala:26)
      at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:134)
      at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:104)
      at git_log.StraightPyCall$.main(StraightPyCall.scala:19)
      at git_log.StraightPyCall.main(StraightPyCall.scala)
  </code></pre>
  
  <p>When I tried executing the command that is printed on the console. It works perfectly fine.</p>
  
  <pre><code>python -c "import sys;sys.path.append('~/playground/octagon/bucket/pythonCheck'); from greeting import *; greet('John')"
  </code></pre>
  
  <p>Result:-</p>
  
  <blockquote>
    <p>hey John</p>
  </blockquote>
  
  <p>Note : Below is the ProcessBuilder toString representation (copied from stacktrace while debugging) :-</p>
  
  <pre><code>[python, -c, "import, sys;sys.path.append('/Users/mogli/jgit/code-conf/otherScripts/pythonScripts/CallRelativePyFromBash/pyscripts');, from, Greet, import, *;, greet_with_arg('John')"]
  </code></pre>
  
  <p>Kindly suggest, what needs to be modified in commandWithNewLineInBeginning to make it work from scala</p>