java - readLine() hangs on last line using Runtime.exec and BufferedStream -


I am using the right practices mentioned in this article:

I've read output and error streams together. However, when reading the output stream of the process, it hangs on readLine () after the last line I have no idea how it works. This is the line of process and it just hangs there.

This hanging order paexec \ 192.168.1.92 -c -f C: \ Windows \ ITBBsync0.bat.

There are several lines inside the batch file such as the following: devcon.exe status = usb> c: \ windows \ output.txt

When I execute it on the command line, So the code exits 0. When I execute it in Java it is hanging after reading the last line of output (which is basically the last line of the batch file). I believe the process is not finished, so why does this problem occur?

  import java.io. *; Class StreamGobbler Thread is Extended {InputStream; String type; StreamGobbler (InputStream, string type) is {this.is =; This.Type = type; } Public Zero Run () {try {InputStreamReader isr = new InputStreamReader (is); Buffed reader br = new buffed reader (ISR); String line = null; While ((line = br.readline ()) = null {{System.out.println (type + "& gt;" + line); // hanging after reading the last line}} hold (IOException ioe) {Io.printStackTrace ();}}}  

In addition to this, the method that uses StreamGobbler is as follows: Clearly there is a basic class that executes this method.

Public Stable Boolean CMD (String Command) {Try {Runtime RT = Runtime.GetTermetime (); System.out.println ("Execution" + Command); Process P = rt.exec (command); // An error message? Streambobler errorGobler = new streambobbler (P. gate erroostream ("error"); streambobler output GABBLER = new streambobbler (P.JetInputStream (), "Output "); ErrorGobbler.start (); outputGobbler.start (); Int exitVal = p.waitFor (); if (ExitVal! = 0) {System.out.println (" ExitValue: "+ ExitVal); System.out. Println (command + "exit code:" + exit); details are false;} back true;} hold (IOException ioe) {io.printStackTrace (); description is false;} grip (ie impaired exception) {ie. Pri NtStackTrace (); return false; }}

I have visited several threads on stack overflow and as far as I know I am using the best methods for this. Please tell me how I can fix it or why this is happening.

I can not apply to you at all, because I am implementing it because it is a bit complicated, but the application performs some network operations and also executes a batch file which in turn operates more .


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -