2012-02-02 132 views
3

我正在研究一个JSFL脚本,它将导出WAV文件并使用lame.exe通过FLfile.runCommandLine将它们编码为MP3。我无法弄清楚如何在命令行中正确地转义空格以便工作。JSFL:FLfile.runCommandLine&为Windows命令行参数正确地转义空格

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' 不是reconginzed为一个内部或外部 命令,可操作的程序或批处理文件。

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

(简单地删除空间形成环境中的任何路径是不是一种选择。动态生成的COMMAND_LINE var和必须能够与空间应对是对别人有用。)

回答

0

这可能不是问题。你需要逃避你的反斜线:C:\\的路径\\ lame.exe pathWithSpaces”

另一种方法是使用正斜杠,这窗户也明白

+1

嘿你不是xJSFL的家伙吗? :)我会试试这个。 – Mambo4 2012-02-02 19:32:19

+0

这就是我!我通常在这里,因为计划老我虽然:) 你使用的框架? – 2012-02-02 21:31:49

+0

还没有使用xJSFL。我厌倦了扭转斜线,但结果相同。你有这样的例子吗? – Mambo4 2012-02-02 22:22:33

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

希望帮助:)

+0

我们希望避免这种做法,但它可能是唯一的选择。谢谢戴夫! – Mambo4 2012-02-02 23:20:55

+0

我不担心。 xJSFL为一些幕后任务写了一些适当的临时文件到硬盘驱动器,这是没有问题的! – 2012-02-02 23:41:00

+0

顺便说一句 - 如果您想要在不锁定Flash的情况下运行批处理文件,还可以使用START命令:http://www.robvanderwoude.com/ntstart.php – 2012-02-02 23:41:31

0

继大卫的带领下,我结束了这段代码:

//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>”才能获得相同的效果,正如我在this thread中所知道的。

0

您不需要运行.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);