在Windows上的Scala代码中运行shell命令似乎需要命令的完整绝对
发布时间:2020-12-14 01:42:24 所属栏目:Windows 来源:网络整理
导读:当我尝试在Mac上运行 shell命令时,它按预期工作如下: scala import scala.sys.process._import scala.sys.process._scala """protractor --version"""!warning: there were 1 feature warning(s); re-run with -feature for detailsVersion 0.24.0res12: In
当我尝试在Mac上运行
shell命令时,它按预期工作如下:
scala> import scala.sys.process._ import scala.sys.process._ scala> """protractor --version"""! warning: there were 1 feature warning(s); re-run with -feature for details Version 0.24.0 res12: Int = 0 scala> 但如果我在Windows上这样做,我会得到这个: scala> import scala.sys.process._ import scala.sys.process._ scala> """protractor --version"""! warning: there were 1 feature warning(s); re-run with -feature for details java.io.IOException: Cannot run program "protractor": CreateProcess error=2,The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041) 好像我必须在Windows上这样做: scala> import scala.sys.process._ scala> """C:UserstwerAppDataRoamingnpmprotractor.cmd --version"""! warning: there were 1 feature warning(s); re-run with -feature for details Version 0.24.0 res11: Int = 0 scala> 我必须提供命令的完整绝对路径. 但我确信该命令在路径中可用. 反正有没有避免这个?
你可以试试这个:
val command = Seq("protractor","--version") val os = sys.props("os.name").toLowerCase val panderToWindows = os match { case x if x contains "windows" => Seq("cmd","/C") ++ command case _ => command } panderToWindows.! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- haskell – 在Windows 7上安装带有cygwin的Cabal-dev
- windows-server-2012 – 当logonHours受限时,无法联系“无法
- pytesser模块WindowsError错误解决方法
- Windows Azure Powershell部署错误 – “远程服务器返回了意
- windows-server-2012 – 将服务帐户移动到新的OU
- batch-file – 如何在DOS中为文件名添加日期和时间?
- 重新安装Windows后,git stash无法正常工作
- windows – 如何人为地将CPU加载到某个百分点?
- 2018-2019-2 《网络对抗技术》Exp2 后门原理与应用 2016521
- windows-server-2008 – 使用1GB内存运行Windows Server 20
推荐文章
站长推荐
热点阅读