Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to execute shell builtin from Scala
    primarykey
    data
    text
    <p>I need to check some system settings like <code>ulimit -n</code> from Scala script in Linux. Had I to deal with ordinary commands I would use <code>scala.sys.process</code> package like:</p> <pre><code>import scala.sys.process._ println("ls -lha".!!) </code></pre> <p>Unfortunately this doesn't work for shell builtins. Is there any way to catch an output from shell builtin in Scala?</p> <p><strong>Update:</strong></p> <p>I tried the usual trick <code>sh -c "ulimit -n"</code> in several forms with no luck; All the commands below fail:</p> <pre><code>"sh -c 'ulimit -n'".!! "sh -c \"ulimit -n\"".!! """sh -c "ulimit -n"""".!! """sh -c "ulimit -n """ + "\"".!! </code></pre> <p>And I'm getting a runtime error in REPL:</p> <pre><code>-n": 1: Syntax error: Unterminated quoted string java.lang.RuntimeException: Nonzero exit value: 2 at scala.sys.package$.error(package.scala:27) at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131) at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101) at .&lt;init&gt;(&lt;console&gt;:11) at .&lt;clinit&gt;(&lt;console&gt;) at .&lt;init&gt;(&lt;console&gt;:11) at .&lt;clinit&gt;(&lt;console&gt;) at $print(&lt;console&gt;) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704) at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920) at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43) at scala.tools.nsc.io.package$$anon$2.run(package.scala:25) at java.lang.Thread.run(Thread.java:722) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload