I have
val str = s"""/bin/bash -c 'some command'"""
job = Some(str.!!)
It is meant to execute the bash command I assume.
Can someone explain this syntax? Googling for '.!!' doesn't help much neither does 'dot exclamation exclamation' so I hope someone can explain this one and/or point me to the doc.
The job doesn't run and I'm trying to debug the code, but when i put this in a
try {
command = Some(str.!!)
}
catch {
case e:Exception =>
println(e.toString)
}
e is actually not an Exception for some reason... Trying to figure what this really does and how to find what is happening.
In Scala, as in Java, a string is an immutable object, that is, an object that cannot be modified. On the other hand, objects that can be modified, like arrays, are called mutable objects. Strings are very useful objects, in the rest of this section, we present important methods of java. lang.
Any arbitrary expression can be embedded in ${} . For some special characters, it is necessary to escape them when embedded within a string. To represent an actual dollar sign you can double it $$ , like here: Scala 2 and 3.
For many languages, the string "Order" needs a different translation for each of these meanings. In Drupal 7. x and later, it is possible to make different versions of such strings for translation. This is done by adding text to make unique strings for each meaning. This extra text is called string context.
There is an implicit conversion from String
to ProcessBuilder
. When you import scala.sys.process._
then scala will automatically perform the conversion when needed, thus making the method !!
available on String instances. You can find the methods of ProcessBuilder here: http://www.scala-lang.org/api/current/index.html#scala.sys.process.ProcessBuilder
The documentation for !!
says that "If the exit code is non-zero, an exception is thrown." It appears that bash in this case does return 0
, so the command was for some reason successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With