3

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.)

Mambo4
  • 182
  • 7
  • 17

5 Answers5

0

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);
Justin G
  • 776
  • 1
  • 10
  • 25
0

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

0

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.

Dave Stewart
  • 2,324
  • 2
  • 22
  • 24
0

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 :)

Dave Stewart
  • 2,324
  • 2
  • 22
  • 24
  • we were hoping to avoid that approach, but it might be the only option. thanks Dave! – Mambo4 Feb 02 '12 at 23:20
  • I wouldn't worry about it. xJSFL writes a fair few temp files to the hard drive for a bunch of behind-the-scenes tasks, and it's no problem! – Dave Stewart Feb 02 '12 at 23:41
  • By the way - you can also use the START command if you want to run the batch file without locking Flash: http://www.robvanderwoude.com/ntstart.php – Dave Stewart Feb 02 '12 at 23:41
0

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

Community
  • 1
  • 1
Mambo4
  • 182
  • 7
  • 17