0
import java.io.*;
public class NewClass {
    public static void main(String[] args)
    {
        try{
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec("cmd");
            BufferedReader Pop = new BufferedReader(new InputStreamReader(p.getInputStream()));
            BufferedWriter Pin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String newCmd;
            System.out.print("Enter Command : ");
            newCmd = br.readLine();
            String s;
            Pin.write(newCmd + " \n");
            Pin.flush();
            s=Pop.readLine();
            while(s!=null)
            {
                System.out.println(s);
                s = Pop.readLine();
            }
            Pin.close();
            Pop.close();
            p.destroy();
        }
        catch(IOException ex)
        {
            System.out.println(ex.toString());
        }

    }
}

i have created this program to execute the 'cmd' commands but after executing commands the loop is not completing can anyone suggest me how to break the loop...

Thank you....

4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by Taywin
0

The reason the program isnt ended is still the process is running. You have to terminate the process.
Write exit and you will see the program ends.

0

rotten, it is calling cmd.exe to execute a given command line (via the program) on Windows. Supposedly, the given command will run something that returns a value back to the caller.

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.