JSFL:FLfile.runCommandLine & correcting escape spaces for Windows commandline args



我正在编写一个JSFL脚本,该脚本将通过FLfile.runCommandLine导出WAV文件,并使用lame.exe将其编码为MP3。我不知道如何正确地转义命令行中的空格。

var command_line = '"C:pathWithSpaces in pathnamelame.exe" -option1 -option2 "C:different pathWithSpacestargetfile.wav" "C:different pathWithSpacestargetfile.mp3"' ;
FLfile.runCommandLine (command_line);

命令窗口中的结果:

"C:\pathWithSpaces"未重新定义为内部或外部命令、可操作程序或批处理文件。

我试过用"%20"和carrat空格"^"替换空格,但都失败了。var command_line在手动剪切并粘贴到命令窗口时被验证可以工作,只有在JSFL脚本中运行表单时,空格才会出现问题。

(不能简单地从环境中的任何路径中删除空格。command_line var是动态生成的,必须能够处理对其他人有用的空格。)

这可能不是问题所在。您需要转义路径名\\lame.exe中的反斜杠:C:\\pathWithSpaces"

另一种选择是使用前斜杠,windows也理解这一点。

你知道,我可能错了!我尝试了很多选择,但没有成功。我认为这可能与多个论点有关。。。在没有进一步调查的情况下不确定。

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

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"');

希望能有所帮助:)

在Dave的带领下,我得到了以下代码:

//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 pathnamelame.exe");
var command_line ='"' + exe_path + '" -option1 -option2 "C:different pathWithSpacestargetfile.wav" "C:different pathWithSpacestargetfile.mp3"';
FLfile.runCommandLine (command_line);

我想我找到了你的答案。你需要一个额外的报价单。

var filePath = '"c:/somepath"'
var argument = '"argument"'
FLfile.runCommandLine('"'+ filePath + ' ' + argument +'"');

所以你最终通过了一个看起来像的东西

""c:/somepath" "argument""

注意周围的附加引号

最新更新