gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:10:09 25 4
gpt4 key购买 nike

我想编译这个:

import scala.sys.process._

val output = "scala".!!

但向我展示了这个:

java.io.IOException:无法运行程序“scala”:CreateProcess error=2,系统找不到指定的文件

这也不起作用:

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

val output = "cmd".!!

我的环境变量也很好。 (对于 java:C:\Program Files\Java\jdk1.8.0_111\和 scala:C:\Program Files (x86)\scala 和路径变量:%JAVA_HOME%\bin%SCALA_HOME%\bin

在cmd工作中输入“scala”。这段代码也可以工作:

import scala.sys.process._

val output = "java".!!

Windows 10

最佳答案

command scala 是一个带有交互式控制台的 REPL。您正在尝试从交互式控制台运行交互式命令吗?

它应该可以顺利地与任何非交互式命令一起使用,例如 ls -l(dindows 中的 DIR)或 date,如下例所示(在UNIX),

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

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

或者,

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

但是要运行一些交互式进程,例如 ssh 或其他进程,

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

关于java.io.IOException : Cannot run program "scala": CreateProcess error=2,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43987517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com