
com.appium.utils.CommandPrompt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AppiumTestDistribution Show documentation
Show all versions of AppiumTestDistribution Show documentation
A tool run Android and iOS test in parallel across devices
package com.appium.utils;
/**
* Command Prompt - this class contains method to run windows and mac commands
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class CommandPrompt {
Process p;
ProcessBuilder builder;
public String runCommand(String command) throws InterruptedException, IOException {
p = Runtime.getRuntime().exec(command);
// get std output
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
String allLine = "";
int i = 1;
while ((line = r.readLine()) != null) {
allLine = allLine + "" + line + "\n";
if (line.contains("Console LogLevel: debug") && line.contains("Complete")) {
break;
}
i++;
}
return allLine;
}
public BufferedReader getBufferedReader(String command) throws IOException {
List commands = new ArrayList<>();
if (System.getProperty("os.name").toLowerCase().contains("win")) {
commands.add("cmd");
commands.add("/c");
} else {
commands.add("/bin/sh");
commands.add("-c");
}
commands.add(command);
ProcessBuilder builder = new ProcessBuilder(commands);
Map environ = builder.environment();
final Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
return new BufferedReader(isr);
}
public String runCommandThruProcess(String command)
throws IOException {
BufferedReader br = getBufferedReader(command);
String line;
String allLine = "";
while ((line = br.readLine()) != null) {
allLine = allLine + "" + line + "\n";
}
return allLine;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy