1

Here is my problem: I have a .bat file which has a number of commands. When I invoke this bat file from my java program using processbuilder it starts executing the commands in .bat file line by line. However when it reaches the last line which executes a perl program it hangs and the program never ends. It hangs there forever. Any idea why this might be happening. Just for your information there is no problem with the perl code and I'm able to execute

4
  • 1
    Can you run the perl from java, with or without a .bat script? Commented Mar 1, 2011 at 10:36
  • my guess is that the PATH environment var is not set so the perl interpreter is not found. Try supplying the fullpath for tjhe perl interpreter aka: c:\the\path\to\perl\perl.exe ... Commented Mar 1, 2011 at 10:39
  • 1
    I think we'd need to see the batch file and the Perl script to be of any help. See if you can duplicate the buggy behavior in a small example that you can post here. Commented Mar 1, 2011 at 13:25
  • it hangs there forever how do you know ;-) Commented Mar 5, 2011 at 21:36

2 Answers 2

2

Does your perl program write to standard output? I suspect the problem is that a Java process redirects the child process' standard output and standard error output to a pipe. The receiving end of that pipe is connected to the java program, so any child process invoked from java that writes to standard output / error will block if you fail to read its output. You must either eliminate the perl program's output or read the child process' output (Process.getInputStream() and/or Process.getErrorStream()) from within your java program.

Sign up to request clarification or add additional context in comments.

1 Comment

: Hey I was able to fix this problem. All I had to do was to include a statement in my java code which closes the output stream of the process. Without which it was waiting on the command line for the perl program to be executed forever. I'm not exactly sure about the behavior, any information would be help.
0

Hey I was able to fix this problem. All I had to do was to include a statement in my java code which closes the output stream of the process. Without which it was waiting on the command line for the perl program to be executed forever. I'm not exactly sure about the behavior, any information would be help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.