Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Start application, and return process ID (PID)

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Start application, and return process ID (PID)

    Hi!
    I'm start application for my program.
    start code:
    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
    Last edited by prepared91; April 16th, 2011 at 06:58 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Location
    Pune, India
    Posts
    11
    My Mood
    Cool
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Start application, and return process ID (PID)

    Hi,

    If some other application is running, it means there must be problem with program.exe.
    Hardik Jadhav

Similar Threads

  1. Hello.. need help in encryption process
    By apisz8701 in forum Member Introductions
    Replies: 0
    Last Post: February 13th, 2011, 05:03 AM
  2. Kill a process
    By subhvi in forum Java Theory & Questions
    Replies: 5
    Last Post: January 14th, 2010, 09:11 PM
  3. Replies: 0
    Last Post: December 3rd, 2009, 04:43 PM
  4. process control
    By ttsdinesh in forum Java Native Interface
    Replies: 6
    Last Post: October 27th, 2009, 06:29 PM
  5. Patch Process
    By Drakenmul in forum Java Theory & Questions
    Replies: 3
    Last Post: August 2nd, 2009, 03:09 AM