title: Run console command in scala
body: <p>I want to run this command in Scala, although I am facing all sorts of errors: </p>
  
  <pre><code>sed -i '.back' 's/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g' /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf
  </code></pre>
  
  <p>or </p>
  
  <pre><code>sed -i '.back' "s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g" /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf
  </code></pre>
  
  <p>I have listed all my tries here (none works). What is the right way to run this command? </p>
  
  <p>Try 1: </p>
  
  <pre><code>scala&gt; val command = "sed -i '.back' 's/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g' /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf"
  scala&gt; command.! 
  sed: 1: "'s/maxTablesPerQuestion ...": invalid command code '
  res25: Int = 1
  </code></pre>
  
  <p>Try 2: with double quotations: </p>
  
  <pre><code>scala&gt; val command = "sed -i '.back' \"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\" /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf"
  scala&gt; command.! 
  sed: 1: ""s/maxTablesPerQuestion ...": invalid command code "
  res26: Int = 1
  </code></pre>
  
  <p>Try 3: With <code>Seq</code>: </p>
  
  <pre><code>scala&gt; val command = Seq("sed -i '.back' \"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\" /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf")
  scala&gt; command.! 
  java.io.IOException: Cannot run program "sed -i '.back' "s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g" /Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:69)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl.scala:98)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderImpl.scala:112)
    ... 33 elided
  Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 36 more
  </code></pre>
  
  <p>Try 4: with <code>Seq</code>: </p>
  
  <pre><code>scala&gt; val command = Seq("sed -i '.back' \"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\"", "/Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf")
  
  scala&gt; command.!
  java.io.IOException: Cannot run program "sed -i '.back' "s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g"": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:69)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl.scala:98)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderImpl.scala:112)
    ... 33 elided
  Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 36 more
  </code></pre>
  
  <p>Try 5: with <code>Seq</code>:</p>
  
  <pre><code>scala&gt; val command = Seq("sed -i '.back'", "\"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\"", "/Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf")
  
  scala&gt; command.!
  java.io.IOException: Cannot run program "sed -i '.back'": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:69)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl.scala:98)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderImpl.scala:112)
    ... 33 elided
  Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 36 more
  </code></pre>
  
  <p>Try 6: </p>
  
  <pre><code>scala&gt; val command = Seq("sed -i", "'.back'", "\"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\"", "/Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf")
  
  scala&gt; command.!
  java.io.IOException: Cannot run program "sed -i": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:69)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl.scala:98)
    at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderImpl.scala:112)
    ... 33 elided
  Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 36 more
  </code></pre>
  
  <p>Try 7: with <code>Seq</code>: </p>
  
  <pre><code>scala&gt; val command = Seq("sed", "-i", "'.back'", "\"s/maxTablesPerQuestion/maxTablesPerQuestion = 2.0 /g\"", "/Users/i-danielk/ideaProjects/aristo/solvers/tableilp/src/main/resources/application.conf")
  
  scala&gt; command.!
  sed: 1: ""s/maxTablesPerQuestion ...": invalid command code "
  res34: Int = 1
  </code></pre>