0

我想将两个参数传递给 nativeProcess。

当我使用带有参数的 windows 命令运行 exe 文件时,它正在工作。窗口命令是“abc.exe a.txt b.txt”

如何使用 flex nativeProcess 以该格式将两个参数传递给 exe?

这是我到目前为止所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            private var process:NativeProcess;
            protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
            {
                if (NativeProcess.isSupported)
                {
                    callExe();
                }
                else
                {
                    textReceived.text = "NativeProcess not supported.";
                }
            }

            public function callExe():void
            {
                var a_FilePath:String = File.applicationStorageDirectory.resolvePath("dist/a.txt").nativePath;
                var b_FilePath:File = File.applicationStorageDirectory.resolvePath("dist/b.txt").nativePath;

                if (Capabilities.os.toLowerCase().indexOf("win") > -1)
                {
                    var file:File = File.applicationStorageDirectory.resolvePath("dist/abc.exe");
                }

                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

// 我把这行放在下面,它适用于我的情况

nativeProcessStartupInfo.workingDirectory = File.applicationStorageDirectory.resolvePath();

nativeProcessStartupInfo.executable = 文件;

                var args:Vector.<String> = new Vector.<String>();
                args.push(a_FilePath);
                args.push(b_FilePath);

                nativeProcessStartupInfo.arguments = args;

                process = new NativeProcess();
                process.start(nativeProcessStartupInfo);
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
                process.addEventListener(ProgressEvent.PROGRESS, progressEvent);
                process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, errorData);
            }

            public function inputProgressListener(event:ProgressEvent):void
            {
                textReceived.text += "Input Progress Event";
            }
            public function onOutputData(event:ProgressEvent):void
            {
                textReceived.text += "Output Event";
            }
            public function progressEvent(event:ProgressEvent):void
            {
                textReceived.text += "Progress Event";  
            }
            public function errorData(event:ProgressEvent):void
            {
                textReceived.text += "Error Event";
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <mx:TextInput id="textReceived" width="352" height="200"/>

</s:WindowedApplication>
4

1 回答 1

2

我通过以粗体添加以下行来解决我的难题:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            private var process:NativeProcess;
            protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
            {
                if (NativeProcess.isSupported)
                {
                    callExe();
                }
                else
                {
                    textReceived.text = "NativeProcess not supported.";
                }
            }

            public function callExe():void
            {
                var a_FilePath:String = File.applicationStorageDirectory.resolvePath("dist/a.txt").nativePath;
                var b_FilePath:File = File.applicationStorageDirectory.resolvePath("dist/b.txt").nativePath;

                if (Capabilities.os.toLowerCase().indexOf("win") > -1)
                {
                    var file:File = File.applicationStorageDirectory.resolvePath("dist/abc.exe");
                }

                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

// 我把这行放在下面,它适用于我的情况

nativeProcessStartupInfo.workingDirectory = File.applicationStorageDirectory.resolvePath();

nativeProcessStartupInfo.executable = 文件;

                var args:Vector.<String> = new Vector.<String>();
                args.push(a_FilePath);
                args.push(b_FilePath);

                nativeProcessStartupInfo.arguments = args;

                process = new NativeProcess();
                process.start(nativeProcessStartupInfo);
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
                process.addEventListener(ProgressEvent.PROGRESS, progressEvent);
                process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, errorData);
            }

            public function inputProgressListener(event:ProgressEvent):void
            {
                textReceived.text += "Input Progress Event";
            }
            public function onOutputData(event:ProgressEvent):void
            {
                textReceived.text += "Output Event";
            }
            public function progressEvent(event:ProgressEvent):void
            {
                textReceived.text += "Progress Event";  
            }
            public function errorData(event:ProgressEvent):void
            {
                textReceived.text += "Error Event";
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <mx:TextInput id="textReceived" width="352" height="200"/>

</s:WindowedApplication> 
于 2012-04-11T05:45:29.603 回答