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....

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.

what's this program supposed to do?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.