Re: can't get Runtime.getRuntime().exec to work..

John Schultz <[email protected]> Fri, 23 Aug 2002 08:54:56 -0500
Newsgroups gmane.comp.windows.devel.java.general
Message-ID <[email protected]>
The following link is an excellent resource for this kind of thing:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

-----Original Message-----
From: Sohaila Roberts [mailto:[email protected]]
Sent: Friday, August 23, 2002 8:08 AM
To: [email protected]
Subject: [JAVA] can't get Runtime.getRuntime().exec to work..


Hi, I have the following code

            String tmp2 = "hmm";
            String cmd1 = "html2ps -o "+tmp2+".ps "+tmp2+".html";
            System.out.println("going to do "+cmd1);
            Process p = Runtime.getRuntime().exec(cmd1);
            BufferedReader stdInput = new BufferedReader(new
                        InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new
                        InputStreamReader(p.getErrorStream()));
            // read the output from the command
            String s;
            System.out.println("Here is the standard output of the
                command:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }
            //wait for end of process and get exit status
            int status ;
            status = p.waitFor();
            if (status != 0) {
                System.out.println("The command returned a status of " +
                status);
            }

            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command
                (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }


        } catch (InterruptedException intexc) {
          System.out.println("Interrupted Exception on waitFor: " +
            intexc.getMessage());
        } catch (IOException e) {
          System.out.println("ExecuteCmd.main() : " +  e);
        } catch (Exception e) {
          System.out.println("ExecuteCmd.main() : " + e);
        }

and I get the following output

going to do html2ps -o hmm.ps hmm.html
Here is the standard output of the command:

The command returned a status of -1
Here is the standard error of the command (if any):


hmm.ps doesnt get created and i get no errors.. but when i do that command
on the command shell it creates hmm.ps with no problem..

any suggestions why?

thanks
sohaila

You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.