MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Map;

public class MainClass {
    public static void main(String args[]) throws Exception {
        ProcessBuilder launcher = new ProcessBuilder();
        Map<String, String> environment = launcher.environment();
        launcher.redirectErrorStream(true);
        launcher.directory(new File("c:\\"));

        environment.put("name", "var");
        launcher.command("notepad.exe");
        Process p = launcher.start(); // And launch a new process
        BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = output.readLine()) != null)
            System.out.println(line);

        // The process should be done now, but wait to be sure.
        p.waitFor();

    }
}