JSFL:FLfile.runCommandLine正确地转义Windows命令行参数的空格

我正在处理一个JSFL脚本,该脚本将导出WAV文件并使用lame.exe通过FLfile.runCommandLine将它们编码为MP3。 我无法弄清楚如何正确地逃避命令行中的这些空间。

var command_line = '"C:\pathWithSpaces in pathname\lame.exe" -option1 -option2 "C:\different pathWithSpaces\targetfile.wav" "C:\different pathWithSpaces\targetfile.mp3"' ; FLfile.runCommandLine (command_line); 

导致命令窗口:

“C:\ pathWithSpaces”不能作为内部或外部命令,可操作程序或batch file。

我试着用'%20'和carrat-space'^'replace空格,都失败了。 var command_line被validation在手动剪切并粘贴到命令窗口中时工作,在JSFL脚本中运行时空格似乎只是一个问题。

(只是删除环境中任何path的空格不是一个选项,command_line var是dynamic生成的,并且必须能够处理空间以对其他人有用)。

这可能不是问题。 你需要跳过你的反斜杠:C:\\ pathWithSpaces in pathname \\ lame.exe“

另一种方法是使用正斜线,该窗口也可以理解。

你知道,我可能是这个错了! 我尝试了一堆选择,但没有运气。 我认为这可能与多个论点有关…不确定没有进一步的调查。

一个简单的解决方法是只保存命令到一个批处理文件,然后运行:

 var command = '"C:/pathWithSpaces in pathname/lame.exe" -option1 -option2 "C:/different pathWithSpaces/targetfile.wav" "C:/different pathWithSpaces/targetfile.mp3"'; FLfile.write('file:///C|/temp/lame.bat', command); FLfile.runCommandLine('"c:/temp/lame.bat"'); 

希望帮助:)

在戴夫的带领下,我结束了这个代码:

 //get users temp folder& convert to URI var win_tempLamePath =FLfile.getSystemTempFolder()+'lame.bat'; var win_tempLameURI =FLfile.platformPathToURI(win_tempLamePath); //generate proper syntax for windows CMD var win_fileURI = (FLfile.uriToPlatformPath(<URI for target WAV file>); var win_command =('"'+win_uri+'lame.exe" -V0 -h "' + win_fileURI + '.' + wav +'" "' + win_fileURI + '.mp3" 2> "'+ win_fileURI+'.txt'+'"'); //write the command to lame.bat(aka win_tempLameURI) & execute FLfile.write(win_tempLameURI, win_command); FLfile.runCommandLine(win_tempLamePath); 

注意win_command结尾处的块

  2> "'+ win_fileURI+'.txt'+'" 

将LAME.EXE输出到一个文本文件。 通常情况下,“>”在Windows cmd中执行此操作,但LAME.EXE使用奇数输出方法,需要“2>”才能获得相同的效果,正如我在此线程中学到的

你根本不需要运行一个.bat文件。 你的问题是,在调用runCommandLine之前,你没有把路径转换成可执行的URI到平台路径。 你的代码应该是这样的:

 var exe_path = FLfile.uriToPlatformPath("C:\pathWithSpaces in pathname\lame.exe"); var command_line ='"' + exe_path + '" -option1 -option2 "C:\different pathWithSpaces\targetfile.wav" "C:\different pathWithSpaces\targetfile.mp3"'; FLfile.runCommandLine (command_line);