Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.concurrent.Executors;
- import java.util.function.Consumer;
- //Richiede la classe Divoratore: https://pastebin.com/qW2p3Mv7
- public class Main {
- public static void main(String args[]) throws IOException, InterruptedException {
- System.out.print("Lancio di dir o ls nella home directory ");
- boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
- ProcessBuilder builder = new ProcessBuilder();
- if (isWindows) {
- builder.command("cmd.exe", "/c", "dir");
- } else {
- builder.command("sh", "-c", "ls");
- }
- builder.directory(new File(System.getProperty("user.home")));
- Process process = builder.start();
- Divoratore d = new Divoratore(process.getInputStream(), System.out::println);
- Executors.newSingleThreadExecutor().submit(d);
- int exitCode = process.waitFor(); // 0 indica nessun errore.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement