Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        try {
            // create a new process
            Process p = Runtime.getRuntime().exec("notepad.exe");

            // get the error stream of the process and print it
            InputStream error = p.getErrorStream();
            for (int i = 0; i < error.available(); i++) {
                System.out.println(error.read());
            }

            // wait for 10 seconds and then destroy the process
            Thread.sleep(10000);
            p.destroy();

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

    }
}