gpt4 book ai didi

scala - 如何在 scala.js 中使用 scala.sys.process

转载 作者:行者123 更新时间:2023-12-04 15:53:56 24 4
gpt4 key购买 nike

我已将 scala.sys.process._ 导入到我的 scala.js 项目中。这本身不会造成任何问题,但如果我添加一个简单的命令,例如 println("ls".!!),我会收到大量错误,例如

[error] Referring to non-existent class java.lang.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessImplicits.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.package$.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from draw.Main$.main(org.scalajs.dom.raw.HTMLCanvasElement)scala.Unit
[error] called from draw.Main$.$$js$exported$meth$main(org.scalajs.dom.raw.HTMLCanvasElement)java.lang.Object
[error] called from draw.Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] scala.sys.process.Process$
[error] scala.sys.process.package$
[error] draw.Main$
[error] Referring to non-existent class java.io.File
[error] called from scala.sys.process.ProcessCreation.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(scala.collection.Seq,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String,scala.Option,scala.collection.Seq)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessCreation.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.Process$.apply(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.ProcessImplicits.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from scala.sys.process.package$.stringToProcess(java.lang.String)scala.sys.process.ProcessBuilder
[error] called from draw.Main$.main(org.scalajs.dom.raw.HTMLCanvasElement)scala.Unit
[error] called from draw.Main$.$$js$exported$meth$main(org.scalajs.dom.raw.HTMLCanvasElement)java.lang.Object
[error] called from draw.Main$.main
[error] exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error] scala.sys.process.Process$
[error] scala.sys.process.package$
[error] draw.Main$
[error] Referring to non-existent method java.lang.ProcessBuilder.environment()java.util.Map

导入额外的类如java.lang.ProcessBuilder 和java.io.File 对这些错误的内容没有影响。我在这里缺少什么非常简单的东西吗?

谢谢!

最佳答案

您不能简单地将任意 Scala 库导入 Scala.js——虽然语言相同,但环境却大不相同。许多标准的 Scala 库在 SJS 世界中根本不存在,其中许多不能,因为它运行的 JavaScript 环境的限制。它在语法上是合法的,所以它会编译,但在没有库的 Scala.js 版本之前它无法运行。

总的来说,您应该假设像这样的库存在于 SJS 世界中,除非您发现有人专门移植了它。 (老实说,我不知道是否有人为 Node.js 移植了 scala.sys.process;它在浏览器环境中没有多大意义...)

关于scala - 如何在 scala.js 中使用 scala.sys.process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42750637/

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