我想从我的 Flash/Flex/AIR 应用程序中运行一个 .exe 文件,这怎么可能?
我需要构建一个接口(interface)来打开 xls 文件并将其转换为 swf,当我运行 convert.exe infile.xls outFile.swf
。
转换完成后,我需要在我的应用程序中显示所有 swf。
我知道 ActionScript 3.0。
最佳答案
我认为这可以使用 AIR 来完成,因为 2.0 版本使用 NativeProcess
.我不知道你是否可以运行 .exe 文件(因为安全问题),但我知道你可以运行 python 脚本(我已经完成了),所以你可以制作一个调用你的 .exe 文件的 python 脚本
这是 NativeProcess
帮助中的(注释)示例:
// ...
// package and imports declarations
// ...
public class NativeProcessExample extends Sprite
{
// this is the process
public var process:NativeProcess;
public function NativeProcessExample()
{
// we have to know if we can run NativeProcess
if(NativeProcess.isSupported)
setupAndLaunch();
else
trace("NativeProcess not supported.");
}
public function setupAndLaunch():void
{
// we create a NativeProcessStartupInfo, this will tell the what process do you want to run
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("test.py");
nativeProcessStartupInfo.executable = file;
// now create the arguments Vector to pass it to the executable file
var processArgs:Vector.<String> = new Vector.<String>();
processArgs[0] = "foo";
nativeProcessStartupInfo.arguments = processArgs;
// create the process
process = new NativeProcess();
// listen to events for I/O and Errors
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
// run it!
process.start(nativeProcessStartupInfo);
}
// event handlers
public function onOutputData(event:ProgressEvent):void
{
trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
public function onErrorData(event:ProgressEvent):void
{
trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
public function onExit(event:NativeProcessExitEvent):void
{
trace("Process exited with ", event.exitCode);
}
public function onIOError(event:IOErrorEvent):void
{
trace(event.toString());
}
}
希望对你有帮助
关于apache-flex - 如何从 Flash/Flex/AIR 运行 EXE 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4051874/