Created
July 23, 2009 22:23
-
-
Save dejw/153687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package jsolver; | |
| import java.io.*; | |
| /* Klasa pozwalajaca na uruchamianie programow. */ | |
| public class Invoker { | |
| /** Uruchamia polecenie systemowe. | |
| * Wymusza, aby proces sie zakonczyl, zanim funkcja powroci z wynikiem. | |
| * | |
| * @param command polecenie do uruchomienia | |
| */ | |
| public static int command(String command, boolean quiet) { | |
| boolean err = false; | |
| try { | |
| Process process = new ProcessBuilder(command.split(" ")).start(); | |
| String s; | |
| if(!quiet){ | |
| BufferedReader results = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
| while((s = results.readLine())!= null) System.out.println(s); | |
| } | |
| /* Bledy za zawsze wyswietlane */ | |
| BufferedReader errors = new BufferedReader(new InputStreamReader(process.getErrorStream())); | |
| while((s = errors.readLine())!= null) { | |
| System.err.println(s); | |
| err = true; | |
| } | |
| if(err) throw new InvokerException("Blad poczas uruchamiania " + command); | |
| return process.waitFor(); | |
| } catch(Exception e){ | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public static int command(String command){ return command(command, false); } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment