0

I am currently trying to store the value of the PrintWriter OutputStream as a variable (string).

When the code is run at the moment, the line stdin.println("vol"); prints out volume information using Windows CMD.

I want to store the value that is printed in the console as a variable so it can be used later on.

Any help would be much appreciated!

Code:

package cmd_prompt;

import java.io.PrintWriter;

public class my_main {
public static void main(String[] args) {
    String[] command =
    {
        "cmd",
    };
    Process p;
    try {
        p = Runtime.getRuntime().exec(command);

    new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
    new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
    PrintWriter stdin = new PrintWriter(p.getOutputStream());

    stdin.println("vol");

    stdin.close();
     p.waitFor();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

}   
B. Stein
  • 23
  • 1
  • 7
  • 1
    Possible duplicate of [java runtime.getruntime() getting output from executing a command line program](https://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program) – J-Alex May 04 '18 at 16:31
  • Also see https://stackoverflow.com/a/8150065/1110636 – Timir May 04 '18 at 17:25

0 Answers0