Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

launching a process with exec

Status
Not open for further replies.

ice78991

Programmer
Nov 20, 2006
216
The code below uses Java within a coldfusion template

I am trying to launch a process and then terminate it.

If I double click netstat.exe on the desktop in windows and check it
in the task manager, it is automatically removed from the system when it is complete

However, if I launch from java it remains in the task manager after it has finished processing

Is there any way to alter the code below to force windows to purge netstat.exe on completion. I thought about using destroy() but this terminates the process before it has finished

<cfscript>
function exec_cmd(cmd) {
var runtimeClass="";
var out="";
var r="";
var rsnstruct=structNew();

try{
// Initialize the Java class.
runtimeClass=CreateObject("java", "java.lang.Runtime");
// Execute command
r=runtimeClass.getRuntime();
r.exec(cmd);
r.runFinalization();
r.freeMemory();
rsnstruct.success=true;
}

catch(excpt any){
rsnstruct.message=excpt.message;
}

return rsnstruct;

}
command_output = exec_cmd('d:/netstat.exe');
</cfscript>
 
Once you launch the process, you lose the control over it. If you want to terminate it, you'll need to use another OS call like taskkill or something like that.

If you take a look at the API, you will see the methods you're invoking have nothing to do with process finalizations.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top