Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a perl script called pbp that takes an html file as an argument and then creates an output file. Here is my current code. Infile is obtained earlier from a JFile Chooser. I don't get any errors but there is no ouput from the perl script.

try {
            Process p = Runtime.getRuntime().exec(new String[] {"perl", "C:\\Users\\Roger\\Downloads\\The_Long-Awaited_Product_Specification_and_Sample_Files\\casey\\pbp", inFile.getAbsolutePath()});
            p.getInputStream().close();
            p.getOutputStream().close();
            p.getErrorStream().close();
            System.out.println(p.waitFor());
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
share|improve this question
1  
And perl is doing fine from command line? – mpapec May 25 at 16:33
Can you show the relevant parts of the perl script? – Steve P. May 25 at 16:54
The perl works correctly from the command line. – user2420694 May 25 at 17:32

1 Answer

up vote 0 down vote accepted

You will not get the output of per script directly. You need to capture it using the below code:

BufferedReader stdInput = new BufferedReader(new 
     InputStreamReader(p.getInputStream()));


// read the output from the command
System.out.println("EXE OUTPUT");
while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.