Adobe AIR NativeProcess因参数中有空格而失败?
如果在参数中添加空格,则运行NativeProcess时会出现问题Adobe AIR NativeProcess因参数中有空格而失败?,air,Air,如果在参数中添加空格,则运行NativeProcess时会出现问题 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
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);
在上面的代码中,如果我使用
args.push(“废话”)一切正常
如果我使用
args.push(“诸如此类”)程序中断,好像找不到文件一样
似乎我不是唯一一个:
正如他们的一位用户所指出的,这似乎是21世纪尖端SDK的一个可怕限制。即使是Alex Harui也没有答案,他解决了Adobe的每一个bug:)
有什么想法吗 我在JavaScript中使用air2.6sdk,就像这样,即使在空间中也可以正常工作。 请用这个检查你的代码
var file = air.File.applicationDirectory;
file = file.resolvePath("apps");
if (air.Capabilities.os.toLowerCase().indexOf("win") > -1)
{
file = file.resolvePath(appFile);
}
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var args =new air.Vector["<String>"]();
for(i=0; i<arguments.length; i++)
args.push(arguments[i]);
nativeProcessStartupInfo.arguments = args;
process = new air.NativeProcess();
process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(air.ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
process.start(nativeProcessStartupInfo);
var file=air.file.applicationDirectory;
file=file.resolvePath(“应用程序”);
if(air.Capabilities.os.toLowerCase().indexOf(“win”)>-1)
{
file=file.resolvePath(appFile);
}
var nativeProcessStartupInfo=new air.nativeProcessStartupInfo();
nativeProcessStartupInfo.executable=文件;
var args=new air.Vector[“”]();
对于(i=0;i
如果空格嵌套在“”中,则所有后面的命令行都支持空格
因此,如果假设您有一个文件参数:
'test/folder with space/blah'
将其转换为以下格式:
'test/"folder with space"/blah'
可以选择使用过滤器:
我曾经在空气中遇到过这样的问题,我只是在将文本放入数组之前对其进行过滤
import org.casalib.util.ArrayUtil;
此外,在文件名/参数中使用空格是一种非常糟糕的做法,请改用“\u”。这似乎起源于linux。(文件名中的空格问题)更新-解决方案
文件对象通过nativePath或resolvePath生成的字符串使用“\”作为路径。将“\”替换为“/”即可
我在尝试使用NativeProcess调用7za.exe时遇到了同样的问题。如果您尝试访问各种windows目录,整个操作都会失败。即使尝试运行command.exe并调用批处理文件也会失败,因为您仍然必须尝试通过NativeProcessStartupInfo对象上的“参数”传递带有空格的路径
我花了一天的大部分时间试图让它起作用,但它不会起作用。无论“参数”中的空格发生了什么,都会完全破坏路径
命令行中的示例7za.exe:
7za.exe a MyZip.7z“D:\docs\My Games\Some Game Title\Maps\The Map.Map”
这很好。现在用空气中的本机程序试试。空气消毒器是FUBAR
我尝试了无数种方法来输入参数,但都失败了。有趣的是,我可以让它吐出一个zip文件,但zip中没有任何内容。我想这是因为第一个参数集最终起作用,但路径参数失败了
例如:
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”
出于某种原因,这会弹出一个名为bin-debugMyZip.7z的zip文件,但zip是空的
无论AIR在做什么,它都会破坏路径字符串。我尝试过用各种方式在这些路径周围添加引号。没有任何效果
我想我可以从这个示例中调用批处理文件:
但它也失败了,因为它仍然需要通过参数传递路径
有人有幸在NativeProcess中调用7z或处理完整路径吗?所有这些快乐的小教程都不涉及真正的windows文件夹结构。对此进行扩展:其工作原理(请参阅上面的帖子):
因此,类似这样的方法是可行的:
var processArgs = new air.Vector["<String>"]();
var path = "C:\\folder with spaces\\myfile.doc"
var args = path.split(" ")
for (var i=0; i<args.length; i++) {
processArgs.push(args[i]);
};
var processArgs=new air.Vector[“”]();
var path=“C:\\folder with spaces\\myfile.doc”
var args=path.split(“”)
对于(var i=0;i,这在Windws7上适用:
var Xargs:Array = String("/C#echo#a trully hacky way to do this :)#>#C:\\Users\\Benjo\\AppData\\Roaming\\com.eblagajna.eBlagajna.POS\\Local Store\\a.a").split("#");
var args:Vector.<String> = new Vector.<String>();
for (var i:int=0; i<Xargs.length; i++) {
trace("Pushing: "+Xargs[i]);
args.push(Xargs[i]);
};
NPI.arguments = args;
var-Xargs:Array=String(/C#echo#一种非常简单的方法:)#>#C:\\Users\\Benjo\\AppData\\Roaming\\com.eblagajna.eblagajna.POS\\Local Store\\a.a”).split(“#”);
变量args:Vector.=新向量。();
对于(var i:int=0;i如果应用程序路径或参数包含空格,请确保用引号将其括起来。例如,应用程序的路径包含空格C:\Program Files(x86)\Camera\Camera.exe
使用引号,如:
"C:\Program Files (x86)\Camera\Camera.exe"
适用于我的解决方案-将带有_空间的路径_设置为“nativeProcessStartupInfo.workingDirectory”属性。请参见下面的示例:
public function openPdf(pathToPdf:String):void
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("C:\\Windows\\System32\\cmd.exe");
nativeProcessStartupInfo.executable = file;
if (Capabilities.os.toLowerCase().indexOf("win") > -1)
{
nativeProcessStartupInfo.workingDirectory = File.applicationDirectory.resolvePath(pathToPdf).parent;
var processArgs:Vector.<String> = new Vector.<String>();
processArgs[0] = "/k";
processArgs[1] = "start";
processArgs[2] = "test.pdf";
nativeProcessStartupInfo.arguments = processArgs;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
}
公共函数openPdf(pathToPdf:String):无效
}
var nativeProcessStartupInfo:nativeProcessStartupInfo=new nativeProcessStartupInfo();
var file:file=file.applicationDirectory.resolvePath(“C:\\Windows\\System32\\cmd.exe”);
nativeProcessStartupInfo.executable=文件;
if(Capabilities.os.toLowerCase().indexOf(“win”)>-1)
{
nativeProcessStartupInfo.workingDirectory=File.applicationDirectory.resolvePath(pathToPdf).parent;
变量processArgs:Vector.=新向量。();
processArgs[0]=“/k”;
processArgs[1]=“开始”;
processArgs[2]=“test.pdf”;
nativeProcessStartupInfo.arguments=processArgs;
进程=新的NativeProcess();
进程启动(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_输出数据,onOutputData);
}
您使用的是哪个版本。我使用的是最新版本,参数中的空格没有任何问题。您使用的是var args=new air.Vector[“”]();为了初始化argsYes Pradeep,我使用的是Vector,但不是air。Vector,我在air包中没有任何Vector。Vector我相信在顶级包中。另外,我使用的是最新的FB 4.5。我问的是Adobe air版本,我的是2.6。这里不是air.Vector。Vector在顶级包中,否则我的代码几乎和你的一样pt我正在调用cmd.exe,然后将bat作为参数传递,其他参数都在后面。我也已经发布了应用程序,并警告我们不要使用
args.push("C:\\folder");
args.push("with");
args.push("spaces\\myfile.doc");
var processArgs = new air.Vector["<String>"]();
var path = "C:\\folder with spaces\\myfile.doc"
var args = path.split(" ")
for (var i=0; i<args.length; i++) {
processArgs.push(args[i]);
};
var Xargs:Array = String("/C#echo#a trully hacky way to do this :)#>#C:\\Users\\Benjo\\AppData\\Roaming\\com.eblagajna.eBlagajna.POS\\Local Store\\a.a").split("#");
var args:Vector.<String> = new Vector.<String>();
for (var i:int=0; i<Xargs.length; i++) {
trace("Pushing: "+Xargs[i]);
args.push(Xargs[i]);
};
NPI.arguments = args;
"C:\Program Files (x86)\Camera\Camera.exe"
public function openPdf(pathToPdf:String):void
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("C:\\Windows\\System32\\cmd.exe");
nativeProcessStartupInfo.executable = file;
if (Capabilities.os.toLowerCase().indexOf("win") > -1)
{
nativeProcessStartupInfo.workingDirectory = File.applicationDirectory.resolvePath(pathToPdf).parent;
var processArgs:Vector.<String> = new Vector.<String>();
processArgs[0] = "/k";
processArgs[1] = "start";
processArgs[2] = "test.pdf";
nativeProcessStartupInfo.arguments = processArgs;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
}