Start application, and return process ID (PID)
Hi!
I'm start application for my program.
start code:
Code Java:
import java.io.*;
public class runtime{
public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
//Process pr = rt.exec("cmd /c dir");
//Process pr = rt.exec("cmd /c tasklist");
Process pr = rt.exec("cmd /c start /MIN D:/program/program.exe");
//Process pr = rt.exec("c:\helloworld.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
But what is killing program?
How to return application pid?
(some application same name)
(example: notepad.exe (pid 998) (runned)
new--> notepad.exe (pid 999)
(the return pid i save the file first a row.)
how to return actual application pid?
Sorry, but i dont know english. (im from hungary).
Thank you for your helping.
Prepared91
Re: Start application, and return process ID (PID)
Java can't get you the process ID (it's only valid while that other process is running anyways, and can change between runs). What you're getting back is the application exit code. There could be any number of things which would cause your program to terminate, though I doubt Java is one of those. Java does not allow you to access other processes.
Hopefully that helps, I'm not entirely sure what it is you're after.
Re: Start application, and return process ID (PID)
Hi,
If some other application is running, it means there must be problem with program.exe.