File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed
src/main/java/com/thoughtworks/utils Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change 99
1010
1111public class CommandPromptUtil {
12+ String OSType =null ;
13+ public CommandPromptUtil ()
14+ {
15+ OSType = System .getProperty ("os.name" );
16+ }
1217
1318 public String runCommandThruProcess (String command )
1419 throws InterruptedException , IOException {
@@ -34,8 +39,16 @@ public List<String> runCommand(String command)
3439
3540 private BufferedReader getBufferedReader (String command ) throws IOException {
3641 List <String > commands = new ArrayList <>();
37- commands .add ("/bin/sh" );
38- commands .add ("-c" );
42+ if (OSType .contains ("Windows" ))
43+ {
44+ commands .add ("cmd" );
45+ commands .add ("/c" );
46+ }
47+ else
48+ {
49+ commands .add ("/bin/sh" );
50+ commands .add ("-c" );
51+ }
3952 commands .add (command );
4053 ProcessBuilder builder = new ProcessBuilder (commands );
4154 final Process process = builder .start ();
@@ -47,8 +60,16 @@ private BufferedReader getBufferedReader(String command) throws IOException {
4760 public Process execForProcessToExecute (String cmd ) throws IOException {
4861 Process pr = null ;
4962 List <String > commands = new ArrayList <>();
50- commands .add ("/bin/sh" );
51- commands .add ("-c" );
63+
64+ if (OSType .contains ("Windows" ))
65+ {
66+ commands .add ("cmd" );
67+ commands .add ("/c" );
68+ }
69+ else {
70+ commands .add ("/bin/sh" );
71+ commands .add ("-c" );
72+ }
5273 commands .add (cmd );
5374 ProcessBuilder builder = new ProcessBuilder (commands );
5475 pr = builder .start ();
@@ -65,5 +86,4 @@ public String runProcessCommandToGetDeviceID(String command)
6586 }
6687 return allLine .trim ();
6788 }
68-
6989}
You can’t perform that action at this time.
0 commit comments