Reputation: 20788
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.
Upvotes: 8
Views: 2688
Reputation: 1181
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.
Upvotes: 8