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.
}
My reference from the answer: https://gist.github.com/993905
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.
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:
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. :)