Scala 不允许我执行路径包含空格的批处理文件。同样的 Java 代码也可以。什么给出了?
这是我的代码:
var commandsBuffer = List[String]()
commandsBuffer ::= "cmd.exe"
commandsBuffer ::= "/c"
commandsBuffer ::= '"'+vcVarsAll.getAbsolutePath+'"'
commandsBuffer ::= "&&"
otherCommands.foreach(c => commandsBuffer ::= c)
val asArray = commandsBuffer.reverse.toArray
val processOutput = processutils.Proc.executeCommand(asArray,true)
return processOutput
otherCommands
是一个 Array[String]
,包含以下元素:
vcbuild
/rebuild
.sln 文件的路径
vcVarsAll 包含 Visual Studio 的 vcvarsall.bat
的路径。它的路径是C:\tools\microsoft Visual Studio 2005\vc\vcvarsall.bat
。我收到的错误是: 'c:\Tools\Microsoft' 未被识别为内部或外部命令, 可运行的程序或批处理文件。
。
processutils.Proc.executeCommand 具有以下实现:
def executeCommand(params:Array[String],display:Boolean):(String,String) = {
val process = java.lang.Runtime.getRuntime.exec(params)
val outStream = process.getInputStream
val errStream = process.getErrorStream
...
}
从 Java/Groovy 执行的相同代码有效。我做错了什么?
Here's the code I have:
var commandsBuffer = List[String]()
commandsBuffer ::= "cmd.exe"
commandsBuffer ::= "/c"
commandsBuffer ::= '"'+vcVarsAll.getAbsolutePath+'"'
commandsBuffer ::= "&&"
otherCommands.foreach(c => commandsBuffer ::= c)
val asArray = commandsBuffer.reverse.toArray
val processOutput = processutils.Proc.executeCommand(asArray,true)
return processOutput
otherCommands
is an Array[String]
, containing the following elements:
vcbuild
/rebuild
path to a .sln file
vcVarsAll contains the path to Visual Studio's vcvarsall.bat
. It's path is C:\tools\microsoft visual studio 2005\vc\vcvarsall.bat
. The error I receive is:'c:\Tools\Microsoft' is not recognized as an internal or external command,
.
operable program or batch file.
The processutils.Proc.executeCommand
has the following implementation:
def executeCommand(params:Array[String],display:Boolean):(String,String) = {
val process = java.lang.Runtime.getRuntime.exec(params)
val outStream = process.getInputStream
val errStream = process.getErrorStream
...
}
The same code, executed from Java/Groovy works. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,所以我尝试了所有我能想到的组合。最终起作用的是从组合中省略
cmd.exe /c
。Ok, so I tried all the combinations I could think of. What finally worked was omitting
cmd.exe /c
from the combo.