Max
Max

Reputation: 1292

Error In Executing A Batch File From A Java Program

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

Upvotes: 1

Views: 853

Answers (2)

Max
Max

Reputation: 1292

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

Upvotes: 0

gatinueta
gatinueta

Reputation: 447

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.

Upvotes: 2

Related Questions