Bikash Mishra
Bikash Mishra

Reputation: 41

Runtime.exec fails without any exception/warning/error code

This is really weird and eating away my brains. I am using Runtime.exec to start another jvm and it quietly exits even without starting.

        p = Runtime.getRuntime().exec("java classname", null, new File(workdir));

The process exits immediately. I briefly see the process in taskmanager and it goes off. I even tried to capture the output.

        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String errString = "Error Details:\n";
        String line;

        while((line = br.readLine()) != null)
            errString = errString.concat(line).concat("\n");

The line is null at the first readline call. I know i could use ProcessBuilder but i am on java 1.4 and i cannot go for 1.5. Please help.

Thanks, Bikash

Upvotes: 3

Views: 2529

Answers (2)

Adriaan Koster
Adriaan Koster

Reputation: 16209

I always point to this site when people are having problems with Runtime.exec()

Upvotes: 1

Louis Q
Louis Q

Reputation: 176

Try putting the commands in a command line array:

Runtime.getRuntime().exec(new String[] {"java", "classname"}, null, new File(workdir));

Upvotes: 1

Related Questions