Scala does not allow me to execute a batch file whose path contains spaces. This java code does. What gives?

Here is 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

otherCommandsis Array[String]containing the following elements:

  • vcbuild

  • /rebuild

  • path to the .sln file

vcVarsAll contains the path to Visual Studio vcvarsall.bat. This is the way C:\tools\microsoft visual studio 2005\vc\vcvarsall.bat. The error that I get: 'c:\Tools\Microsoft' is not recognized as an internal or external command, operable program or batch file..

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 that runs from Java / Groovy is executed. What am I doing wrong?

+3
source share
1 answer

Ok, so I tried all the combinations that I could think of. What finally worked was omitted cmd.exe /cfrom the combo.

0
source

Source: https://habr.com/ru/post/1736788/


All Articles