3

我正在开发一个 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' 不是内部或外部命令、可运行程序或批处理文件。

我试过用'%20'和carrat-space'^'替换空格,都失败了。var command_line 在手动剪切并粘贴到命令窗口时经过验证可以正常工作,只有在 JSFL 脚本中运行表单时,空格似乎才是问题。

(简单地从环境中的任何路径中删除空格不是一种选择。命令行变量是动态生成的,并且必须能够处理空格才能对其他人有用。)

4

5 回答 5

0

在 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>”才能获得相同的效果,正如我在这个线程中学到的那样

于 2012-02-03T17:50:48.890 回答
0

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

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

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

希望有帮助:)

于 2012-02-02T22:51:17.293 回答
0

这可能不是问题。您需要转义反斜杠: C:\\pathWithSpaces in pathname\\lame.exe"

另一种方法是使用正斜杠,windows 也可以理解。

于 2012-02-02T17:51:40.410 回答
0

您根本不需要运行 .bat 文件。您的问题是在调用runCommandLine. 您的代码应如下所示:

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);
于 2015-08-01T00:53:16.547 回答
0

我想我找到了你的答案。您需要额外的周边报价。

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

所以你最终传递了一些看起来像

""c:/somepath" "argument""

注意周围的附加引号

于 2018-04-19T06:25:30.677 回答