Skip to content

Commit 5343b2f

Browse files
authored
file with logic of execution everything from input arguments
1 parent a8b2021 commit 5343b2f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • console/java-bash-run/src/main/java/utility
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package utility;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
/*
8+
java -classpath java-bash-run-1.0.jar utility.Main ls -la
9+
*/
10+
11+
public class Main {
12+
public static void main(String[] args) throws IOException, InterruptedException {
13+
// process = Runtime.getRuntime().exec("/bin/sh -c ls ."));
14+
Process process = new ProcessBuilder(args).start();
15+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
16+
String nextLine = null;
17+
while ((nextLine = reader.readLine()) != null) {
18+
System.out.println(nextLine);
19+
}
20+
}
21+
;
22+
int exitCode = process.waitFor();
23+
System.out.println(exitCode);
24+
}
25+
}

0 commit comments

Comments
 (0)