0

I know how to run an external program in java:

public class Test {
  public static void main(String[] args) throws Exception {
    Process p = Runtime.getRuntime().exec(
       "\"c:/my-simple-app.exe\"");
    p.waitFor();
  }
}

But how can I get all of the program properties when I run it like this? I mean: system time for this process (how much system time it took to run), cpu usage (only for this exact process), ... Is it possible?

mazix
  • 2,540
  • 8
  • 39
  • 56

1 Answers1

2

Run this program in a separate thread, then run tasklist /v process (if Windows), intercept output, split lines into columns, find my-simple-app.exe and get necessary info. If tasklist info is not enough, then read process ID column form tasklist output and run some other util to get more info.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • 1
    ok but lets say that my program which I ran from Java end before I can get this info, what then? I would like to make it that way: 1. run an external program in Java 2. wait for it to end 3. get the parameters I wrote about earlier - cp usage, system time for this program. If it isnt possible in Java, maybe in ay other language ... ? – mazix Jun 19 '13 at 10:27
  • 1
    I think it's only possible if my-simple-app.exe will be getting this info about itself while running and writing it to stdout which you can intercept and read – Evgeniy Dorofeev Jun 19 '13 at 10:40