在命令提示符下我的按钮preSS怎么能执行一个命令,并回到原来的动作输出? [英] How can i on button press execute a command in the command prompt and get back the output in ActionScript?

查看:205
本文介绍了在命令提示符下我的按钮preSS怎么能执行一个命令,并回到原来的动作输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Flex的GUI。我有一个条件,正如我需要执行一些命令行参数在本地机器上,并得到结果返回或输出返回到一个文本框区域。我该怎么办就提出,在本地计算机上执行命令,并返回输出?一个按钮

I have a GUI using Flex. I have a condition like i need to execute some command line arguments in the local machine and get the results back or output back to a textbox area. How can i do a button on submit, execute command in the local machine and return the output?

Command to execute example: 

    echo logfile.log | grep username

Code:

button1.onRelease = function () 
{
    // in this computer, it will now run a command, please wait.
}

我的答案参考: https://gist.github.com/993905

推荐答案

你不会是能够使用ActionScript 2做到这一点,你不会是能够做到这一点使用ActionScript 3的Flash网络播放器。有一些工具,你可以用它来创建使用ActionScript 2和3,添加这种扩展功能的投影机,但是从网络,你不能简单地做到这一点,因为这当然是一个极端的安全隐患。

You're not going to be able to do this using actionscript 2 and you're not going to be able to do this using actionscript 3 in the flash web player. There are certain tools you can use to create projectors using actionscript 2 and 3 to add this kind of extended capability but you cannot simply do it from the web, as of course this would be an extreme security risk.

不过,您可以与Adobe AIR 2.0或更高做到这一点。您可以使用NativeProcess类检测操作系统,启动终端或CMD.EXE,然后你可以针对它运行的命令。下面是我在一个项目开发运行使用AIR就像你正在试图做对OS命令一些code:

However, you can do this with Adobe AIR 2.0 or greater. You use the NativeProcess class and detect the operating system, launch the terminal or cmd.exe and then you can run commands against it. Below is some code from a project I developed to run commands against the OS using AIR just as you're trying to do:

            private var os:String;
            private var consoleExecutable:File;
            private var consoleNativeProcess:NativeProcess;

            private function usbMounted(e:StorageVolumeChangeEvent):void 
            {
                //status.appendText('Device: ' + e.storageVolume.name + ' mounted to drive: ' + e.storageVolume.drive + '\n');

                os = Capabilities.os.substr(0, 3).toLowerCase();

                switch (os) 
                {
                    case "win":
                        //Windows OS
                        var rootDirs:Array = File.getRootDirectories();

                        var i:int = 0;
                        for (i; i < rootDirs.length; ++i) {
                            consoleExecutable = rootDirs[i] as File;
                            consoleExecutable  = consoleExecutable.resolvePath("Windows");
                            if (consoleExecutable.exists == true) {
                                consoleExecutable = consoleExecutable.resolvePath("System32");
                                consoleExecutable = consoleExecutable.resolvePath("cmd.exe");
                                i = rootDirs.length;                                    
                            }                   
                        }

                    break;

                    case "lin":
                        //Linux OS

                    break;

                    case "mac":
                        //Mac OS

                    break;

                    case "iph":
                        //Iphone OS

                    break;
                }   

                var consoleNativeProcessStartupNfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                consoleNativeProcessStartupNfo.executable = consoleExecutable;
                var startupArgs:Vector.<String> = new Vector.<String>();

                startupArgs.push('/C fsutil fsinfo volumeinfo ' + e.storageVolume.drive + ':');

                consoleNativeProcessStartupNfo.arguments = startupArgs;         
                consoleNativeProcess = new NativeProcess();
                consoleNativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, consoleOutput);           
                consoleNativeProcess.start(consoleNativeProcessStartupNfo);         
                consoleNativeProcess.closeInput();
            }       

            private function consoleOutput(e:ProgressEvent):void 
            {
                var consoleOuput:String = consoleNativeProcess.standardOutput.readUTFBytes(consoleNativeProcess.standardOutput.bytesAvailable);

                switch (os) 
                {
                    case "win":
                        //Windows OS

                    break;

                    case "lin":
                        //Linux OS

                    break;

                    case "mac":
                        //Mac OS

                    break;

                    case "iph":
                        //Iphone OS

                    break;
                }

                consoleNativeProcess.exit();
            }

所以,code应该是pretty的直线前进。它可能不是所有的在那里就像我刚才复制的code处理本机进程的​​启动,输出和终止部分。然后我删除的code,它是敏感部位。基本上,你只是得到的操作系统信息,浏览到可执行文件的路径,请检查是否存在,如果是这样,将其启动,针对它运行一个命令,等待输出。我把在switch语句处理输出的时候也检查操作系统,因为它是安全的假设你下一步的产量也将取决于操作系统(或至少在我的情况下,它是)。如果您需要更多的帮助,理解这一切我建议使用Google上的Adobe AIR本机进程API的教程或只是张贴一些问题在这里。 :)

So the code should be pretty straight forward. It might not all be there as I've just copied the portion of the code dealing with the native process startup, output and termination. I then deleted parts of the code that were sensitive. Basically you're just getting the OS info, navigating to the path of the executable, check to see if it exists and if so, start it up, run a command against it and wait for output. I put in a switch statement to check the OS when handling the output as well, since it's safe to assume what you do next with the output will also be OS dependent (or at least in my case it was). If you need more help understanding all this I suggest googling for a tutorial on the Adobe AIR Native Process API or just post some more questions here. :)

这篇关于在命令提示符下我的按钮preSS怎么能执行一个命令,并回到原来的动作输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆