I have a system that encodes videos by using a series of command-line tools. Formally, I had AIR modify a file. That change was detected by Directory Monitor, which would then start the first batch file, which would call a PERL script to mangle the data coming in, which would create another batch file, and then the root batch file starts that running. That batch finally calls the format-specific batch file that actually has the commands for encoding. That calls multiple other programs, taking screenshots, resizing the video, packaging it into an MP4, and so on. I wanted to cut out Directory Monitor (the less extra apps you need installed, the better), and do it all from AIR. Now, I can call the root batch file (the first one), but I can't see the terminal, and for some reason AIR won't let me really call another batch file. I need to call many programs and other batch files, so this isn't going to work. I currently re-rout the output to a <p> tag to show what's going on. I know it's not a display problem, because encoding requires 100% of all my processor, and they are all dead, so...
Anyway, here's my code (except the batch files. Just create two batch files, one that calls the other and use AIR to initiate the first one. It won't call the second).
/* Testing the new NativeProcess */
// Check if native process is even supported
/* We first create a file object and attach it to our executable file. We pass that into a startupInfo object, which will be used to initialize the program. We will include in that our arguments to pass into the native application when it is started. "Native application" means that it's a Windows app, not AIR. We also, need to create a process handle, attach listeners (so we can pass in information and get the output into AIR to play with). Finally, we start the application. */
var file = new air.File();
//file = file.resolvePath("C:\\Documents and Settings\\me\\Desktop\\app\\folder\\\\TestScript.bat"); // Doesn't work. Cannot start a .bat process.
file = file.resolvePath("C:\\WINDOWS\\system32\\cmd.exe");
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
encodeProcess = new air.NativeProcess();
// Attach listeners to catch all outgoing data (through STDOUT), and to allow us to give additional input, if desired.
encodeProcess.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, outputHandler); // Listener on STDOUT
encodeProcess.addEventListener(air.ProgressEvent.STANDARD_INPUT_PROGRESS, inputHandler); // Triggered by NativeProcess object when STDIN stream is flushed.
encodeProcess.addEventListener(air.NativeProcessExitEvent, processExited); // Triggered when the application exits. We need to remove all handles and listeners.
// Start the application.
// Create string to pass through as a command to our first batch file, and pass it through.
var command = "\"" + applicationRoot + "\\program directory\\TestScript.bat\"\n";
alert("NativeProcess is not supported!");
} // End makeItGo()
/* When the application outputs something on STDOUT, we catch that event (the data) in the function below */
var consoleBox = document.getElementById("consoleOutput");
var data = encodeProcess.standardOutput.readUTFBytes(encodeProcess.standardOutput.bytesAvailable);
consoleBox.innerText += data;
/* Whenever input is sent to the console, this function makes sure the new output is shown in the console. Not sure it's needed, but it works with it in. */
/* This takes commands that we type in, and passes it along. */
var inputBox = document.getElementById("consoleInput");
inputBox.value = "";
/* Removes all listeners, closes the process, and removes the AIR handle on the process, allowing it to close. */
encodeProcess.exit(false); // False means don't force the exit.