The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.lang  [58 examples] > Commands  [3 examples]

e90. Reading Output from a Command

    try {
        // Execute command
        String command = "ls";
        Process child = Runtime.getRuntime().exec(command);
    
        // Get the input stream and read from it
        InputStream in = child.getInputStream();
        int c;
        while ((c = in.read()) != -1) {
            process((char)c);
        }
        in.close();
    } catch (IOException e) {
    }

 Related Examples
e89. Executing a Command
e91. Sending Input to a Command

See also: Arrays    Assertions    Classes    Numbers    Objects    Strings    System Properties    Threads   


© 2002 Addison-Wesley.