0

As reported here Execute external command in order to run an external shell command or script in Scala the right code should be:

import scala.sys.process._
val cmd = "ls -l /home" // Your command
val output = cmd.!! // Captures the output

I've noticed this works for some commands but not for others like "java -version" (especially if they have dash "-" before arguments)

Is there a correct way to execute commands like "python --version" or a more complex python script like "python /path/to/my_script.py -x value -y value" ?

1 Answer 1

2

Seems to work with dashes

$ scala
Welcome to Scala 2.13.6 (Eclipse OpenJ9 VM, Java 1.8.0_292).
Type in expressions for evaluation. Or try :help.

scala> import scala.sys.process._
import scala.sys.process._

scala> "java -version".!!
openjdk version "1.8.0_292"
...

scala> "python3 --version".!!
val res1: String =
"Python 3.8.5
"
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it works. I've fined out it was a bug of the application (Lucidworks Fusion 4.2.5) I'm using for my project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.