Accepted answer

You can take advantage of the fact that Scala's ProcessBuilder methods also accept Seq[String].

import sys.process._
object SO {
  def runCommand(cmd: String*): (Int, String, String) = {
    val stdoutStream = new
    val stderrStream = new
    val stdoutWriter = new
    val stderrWriter = new
    val exitValue =
      cmd.!(ProcessLogger(stdoutWriter.println, stderrWriter.println))
    (exitValue, stdoutStream.toString, stderrStream.toString)

  def main(args: Array[String]): Unit = {
    val code =
        |import sys

    val arg = 3
    println(runCommand("python3","-c", code, arg.toString))

Related Query

More Query from same tag