views:

316

answers:

0

I have next command to run from my AIR application:

chp.exe cmd /d /c ""process.bat" "params.tmp" > "log.tmp" 2>&1 && echo 0 > status.tmp" || echo 1 > "status.tmp""

It creates background invisible process and logs output and exit status of the process.bat to the log.tmp

and status.tmp.

chp.exe is a "Create Hidden Process" program (http://www.commandline.co.uk/chp/) that runs programs

invisibly.

Question is how to get output (which is the cmd process ID) from the chp.exe so that I'll be able to kill

the process? I've tried

chp.exe cmd /d /c ""process.bat" "params.tmp" > "log.tmp" 2>&1 && echo 0 > "status.tmp" || echo 1 > "status.tmp"" > pid.tmp

and it works from console, but doesn't work when I call the command from my AIR application. I guess

that problem is in the FluorineFx Aperture Framework (http://aperture.fluorinefx.com/) which I am using

to run external programs from AIR:

private var execProxy:LocalObject;
public function ShellManager()
{
    execProxy = new LocalObject();
    execProxy.source="apsystem:26338E77-36A6-46FF-91CA-79E91079A81C";
    execProxy.addEventListener(FaultEvent.FAULT, execProxyFaultHandler);
    execProxy.addEventListener(ResultEvent.RESULT, execProxyExecuteHandler);
    var aMethod:method = new method();
    aMethod.name  = "Execute"
    execProxy.methods = [aMethod];
}

public function exec():void
{
    var chpPath:String = "D:\\TESTS\\RUNMINIMIZED\\chp.exe";
    var commandString:String = "cmd /d /c \"\"D:\\TESTS\\RUNMINIMIZED\\process.bat\" \"D:\\TESTS\\RUNMINIMIZED\\params.tmp\" > \"D:\\TESTS\\RUNMINIMIZED\\log.tmp\" 2>&1 && echo 0 > \"D:\\TESTS\\RUNMINIMIZED\\status.tmp\" || echo 1 > \"D:\\TESTS\\RUNMINIMIZED\\status.tmp\"\" > \"D:\\TESTS\\RUNMINIMIZED\\pid.tmp\"";
    var tokenExecute:AsyncToken = execProxy.Execute("open", chpPath, commandString);
    ...
}

It seems for me that with the aperture framework the command line looks like

<fluorineInvoker> chp.exe cmd /d /c ""process.bat" "params.tmp" > "log.tmp" 2>&1 && echo 0 > "status.tmp" || echo 1 > "status.tmp"" > pid.tmp

so that the "> pid.tmp" refers to the fluorineInvoker not to the chp.exe. I've also tried

var chpPath:String = "> \"D:\\TESTS\\RUNMINIMIZED\\pid.tmp\" \"D:\\TESTS\\RUNMINIMIZED\\chp.exe";

without any success as well (aperture error: "EcecProxy fault: [RPC Fault faultString="Invoke failed"

faultCode="Aperture.Error.Invoke" faultDetail="Unspecified error"]")

Perhaps there is another easier way? Any thoughts will be appreciated.