Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting command prompt output instantly?
    primarykey
    data
    text
    <p>Probably a misleading title, but thanks to people on my other question, I got my program somewhat working, though now not sure what to do.</p> <p>Here is my method to run command prompt commands and return the output</p> <pre><code>public static String cmdExec(String cmdLine) { String line; String output = ""; try { Process p = Runtime.getRuntime().exec(cmdLine); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { output += (line + '\n'); } input.close(); } catch (Exception ex) { ex.printStackTrace(); } return output; } </code></pre> <p>It works how I want it to work, though now when I run this method, it is going to wait until everything is done, and then return the output, which is not what I want.</p> <p>I made a ping flooding method that uses the cmdExec method. Here is how I call cmdExec()</p> <pre><code>String[] input = ipTextField.getText().split(":"); if(input.length == 2) { System.out.println(cmdExec("cmd /c ping " + input[0] + " -t -n " + Integer.parseInt(input[1]))); </code></pre> <p>So now for instance, if I type "127.0.0.1:3" in my program, it's going to send 3 packets to localhost. Now the problem here is, instead of printing out the lines I get as output from command prompt 1 by 1, it's going to wait until all the 3 packets are sent, and then print the output full output.</p> <p>If I type "ping 127.0.0.1 -t -n 3" in command prompt, it's going to print the reply 1 by 1, not all just at once, so how would I go about doing the same in my program?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload