Skip to content

Commit 17a0a3e

Browse files
author
ttllonsaikrisv
committed
2 parents 2414400 + 802c543 commit 17a0a3e

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/main/java/com/thoughtworks/utils/CommandPromptUtil.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010

1111
public 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
}

0 commit comments

Comments
 (0)