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

发布于 2025-01-02 11:27:39 字数 654 浏览 0 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掩饰不了的爱 2025-01-09 11:27:39

这可能不是问题所在。您需要转义反斜杠: 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.

把回忆走一遍 2025-01-09 11:27:39

你知道,我在这件事上可能是错的!我尝试了很多选择,但没有运气。我认为这可能与多个论点有关......如果没有进一步调查就不确定。

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

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

希望有帮助:)

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:

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

Hope that helps :)

为你鎻心 2025-01-09 11:27:39

按照 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);

Note chunk at the end of win_command

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

是将 LAME.EXE 输出到文本文件。通常为“>”在 Windows cmd 中执行此操作,但 LAME.EXE 使用奇怪的输出方法,需要“2>”达到相同的效果,正如我在 此线程

Following Dave's lead, I ended up with this code:

//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);

Note chunk at the end of win_command

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

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

独自唱情﹋歌 2025-01-09 11:27:39

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

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:

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);
三月梨花 2025-01-09 11:27:39

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

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

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

""c:/somepath" "argument""

注意额外的引号的内容

I think I found your answer. You need an additional surrounding quotation.

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

So you end up passing in something that looks like

""c:/somepath" "argument""

note the additional surrounding quotation marks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文