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' 未被识别为内部或外部 命令、可运行程序或批处理文件。
我尝试用 '%20' 和 carrat-space'^ ' 替换空格,但都失败了。 当手动剪切并粘贴到命令窗口中时,var command_line 已被验证可以工作,空格似乎仅在 JSFL 脚本中运行时才成为问题。
(简单地从环境中的任何路径中删除空格不是一个选项。command_line var 是动态生成的,并且必须能够处理对其他人有用的空格。)
I am working on a JSFL script that will export WAV files and use lame.exe to encode them as MP3, via FLfile.runCommandLine. I can't figure out how to properly escape the spaces in the command linefor this to work.
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);
result in command window:
'C:\pathWithSpaces' is not reconginzed as an internal or external
command, operable program or batch file.
I've tried replacing spaces with'%20' and with carrat-space'^ ', both fail.
The var command_line is verified to work when cut and pasted manually into the command window, the spaces only seem to be an issue when run form within the JSFL script.
(simply removing spaces form any paths in the environment is not an option. The command_line var is dynamically generated, and must be able to cope with spaces to be useful to others.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能不是问题所在。您需要转义反斜杠: C:\\pathWithSpaces in pathname\\lame.exe"
另一种方法是使用正斜杠,Windows 也可以理解。
That's probably not the problem. You need to escape your backslashes: C:\\pathWithSpaces in pathname\\lame.exe"
The alternative is to use forward slashes, which windows also understands.
你知道,我在这件事上可能是错的!我尝试了很多选择,但没有运气。我认为这可能与多个论点有关......如果没有进一步调查就不确定。
一个简单的解决方法是将命令保存到批处理文件然后运行:
希望有帮助:)
You know, I could be wrong about this one! I tried a bunch of options but no luck. I think it may have something to do with multiple arguments... not sure without further investigation.
An easy workaround though is to just save the command to a batch file then run that:
Hope that helps :)
按照 Dave 的指导,我最终得到了以下代码:
Note chunk at the end of win_command
是将 LAME.EXE 输出到文本文件。通常为“>”在 Windows cmd 中执行此操作,但 LAME.EXE 使用奇怪的输出方法,需要“2>”达到相同的效果,正如我在 此线程
Following Dave's lead, I ended up with this code:
Note chunk at the end of win_command
Is to have LAME.EXE output to a text file. Normally ">" does this in windows cmd, but LAME.EXE uses an odd output method that requires "2>" for the same effect, as I learned in this thread
您根本不需要运行 .bat 文件。您的问题是,在调用
runCommandLine
之前,您没有将可执行 URI 的路径转换为平台路径。您的代码应如下所示:You don't need to run a .bat file at all. Your problem is that you're not converting the path to your executable URI to a platform path before calling
runCommandLine
. Your code should look like this:我想我找到了你的答案。您需要额外的周边报价。
所以你最终会传递一些看起来像
注意额外的引号的内容
I think I found your answer. You need an additional surrounding quotation.
So you end up passing in something that looks like
note the additional surrounding quotation marks