air

Adobe AIR NativeProcess fails with spaces in arguments?


I have a problem running the NativeProcess if I put spaces in the arguments



if (Capabilities.os.toLowerCase().indexOf("win") > -1)
{
  fPath = "C:\\Windows\\System32\\cmd.exe";
  args.push("/c");
  args.push(scriptDir.resolvePath("helloworld.bat").nativePath);                
}

file = new File(fPath);

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;                     

args.push("blah");

nativeProcessStartupInfo.arguments = args;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);

in the above code, if I use

args.push("blah") everything works fine

if I use

args.push("blah blah") the program breaks as if the file wasn't found.

Seems like I'm not the only one:

http://tech.groups.yahoo.com/group/flexcoders/message/159521

As one of the users their pointed out, it really seems like an awful limitation by a cutting edge SDK of 21st century. Even Alex Harui didn't have the answer there and he's known to workaround every Adobe bug:)

Any ideas?


Solution

  • UPDATE - SOLUTION

    The string generated by the File object by either nativePath or resolvePath uses "\" for the path. Replace "\" with "/" and it works.


    I'm having the same problem trying to call 7za.exe using NativeProcess. If you try to access various windows directories the whole thing fails horribly. Even trying to run command.exe and calling a batch file fails because you still have to try to pass a path with spaces through "arguments" on the NativeProcessStartupInfo object.

    I've spent the better part of a day trying to get this to work and it will not work. Whatever happens to spaces in "arguments" totally destroys the path.

    Example 7za.exe from command line:

    7za.exe a MyZip.7z "D:\docs\My Games\Some Game Title\Maps\The Map.map"

    This works fine. Now try that with Native Process in AIR. The AIR arguments sanitizer is FUBAR.

    I have tried countless ways to put in arguments and it just fails. Interesting I can get it to spit out a zip file but with no content in the zip. I figure this is due to the first argument set finally working but then failing for the path argument.

    For example:

    processArgs[0] = 'a'; processArgs[1] = 'D:\apps\flash builder 4.5\project1\bin-debug\MyZip.7z'; processArgs[2] = 'D:\docs\My Games\Some Game Title\Maps\The Map.map';

    For some reason this spits out a zip file named: bin-debugMyZip.7z But the zip is empty.

    Whatever AIR is doing it is fraking up path strings. I've tried adding quotes around those paths in various ways. Nothing works.

    I thought I could fall back on calling a batch file from this example: http://technodesk.wordpress.com/2010/04/15/air-2-0-native-process-batch-file/

    But it fails as well because it still requires the path to be passed through arguments.

    Anyone have any luck calling 7z or dealing with full paths in the NativeProcess? All these little happy tutorials don't deal with real windows folder structure.