繁体   English   中英

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

[英]How to use scala.sys.process with scala.js

我已将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 ;它在浏览器环境中没有多大意义......)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM