oczek.scala
oczek.scala

Reputation: 51

java.io.IOException: Cannot run program "scala": CreateProcess error=2,

I want to compile this:

import scala.sys.process._

val output = "scala".!!

but shows me this:

java.io.IOException: Cannot run program "scala": CreateProcess error=2, The system cannot find the file specified

this does't work too:

val cmd = "\"C:\\Program Files (x86)\\scala\\bin\\scalac.bat\\\""

val output = "cmd".!!

also my environment variables are fine. (for java: C:\Program Files\Java\jdk1.8.0_111\ and scala: C:\Program Files (x86)\scala and path variable: %JAVA_HOME%\bin and %SCALA_HOME%\bin

Typing "scala" in cmd work. And this code work too:

import scala.sys.process._

val output = "java".!!

Windows 10

Upvotes: 0

Views: 1757

Answers (1)

prayagupadhyay
prayagupadhyay

Reputation: 31222

command scala is a REPL with interactive console. And you are trying to run interactive command from interactive console?

It should work with any non-interactive commands like ls -l(DIR in dindows) or date smoothly as following examples (in unix),

scala> val output = "date".!!
output: String =
"Mon May 15 14:52:54 PDT 2017
"

or

scala> val output = "java -version".!!
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
output: String = ""

or,

scala> Seq("echo", "urayagppd") #>> new File("mylogs.log")
res2: scala.sys.process.ProcessBuilder =  ( [echo, urayagppd] #| /Users/prayagupd/myrepo/mylogs.log )

But to run something interactive process like ssh or something else,

scala> val scalaProcess = Process("""scala""")
scalaProcess: scala.sys.process.ProcessBuilder = [scala]

scala> val exitCode = scalaProcess.!
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> :quit
exitCode: Int = 1

scala> val p = scalaProcess.run
p: scala.sys.process.Process = scala.sys.process.ProcessImpl$SimpleProcess@af9dd34

scala> Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> :quit

scala> val exitCode = p.exitValue
exitCode: Int = 1

Upvotes: 1

Related Questions