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" ?

Mave751
  • 697
  • 4
  • 11
  • 25

1 Answers1

1

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
"
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • 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. – Mave751 Jun 13 '21 at 11:57