I run code attached below but it gives output only after the command has completed in the String response. I want the console window activated during the running of command and get output of the command.
String command = "src\\youtube-dl"
+ " --max-downloads " + maxdown.getText()
+ " --retries " + noofretry.getText()
+ " --write-all-thumbnails" + sub.getText()
+ " " + url.getText();
String response = "";
try {
Process p = Runtime.getRuntime().exec(command);
InputStream in = p.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = -1;
while((c = in.read()) != -1) {
baos.write(c);
System.out.flush();
response = response + new String(baos.toByteArray());
System.out.println(response);
}
} catch (Exception e) {
e.printStackTrace();
}
youtube-dldirectly, so this question has nothing to do with cmd.exe. The console window is not cmd.youtube-dland it uses full buffering whenStandardOutputis a pipe. It will flush its buffer to the pipe either when its full (typically 4 KB) or at exit. The workarounds are complicated, such as DLL injection and API hooking or actively scraping a console screen buffer.