We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,478 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Break the Loop

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
10 Hours
Discussion Span
9 Months Ago
Last Updated
4
Views
sanket044
Light Poster
43 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Majestics
Practically a Master Poster
696 posts since Jul 2007
Reputation Points: 209
Solved Threads: 66
Skill Endorsements: 5

what's this program supposed to do?

rotten69
Master Poster
747 posts since May 2011
Reputation Points: 36
Solved Threads: 47
Skill Endorsements: 11

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.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0595 seconds using 2.66MB