Package Com.syswin.first;
Import Sun.rmi.runtime.Log;
/**
* @author Yufeifei
* @version November 17, 2017 3:08:24
* Command line class, Cmd/terminal command by this type of operation
* @param cmdstring Command parameters
* */
public class Cmdcommand {
String osname = System.getproperty ("Os.name");
Runtime p = runtime.getruntime ();//Get Current execution environment
/** get the current operating system, execute the appropriate command */
public void ExecCmd (String cmdstring) {
try{
if (Osname.tolowercase (). Contains ("Mac")) {
String command = "/bin/sh" + "-C" + cmdstring;//store terminal commands
Process process = p.exec (command);//execute Terminal command
System.out.println ("The current operating system is:" + osname + "executed command:" + "cmdstring");
}else if (Osname.tolowercase (). Contains ("Win")) {
String command = "cmd.exe/k" + cmdstring;//cmd/c close the Commands window after executing the command. cmd/k do not close command window after executing command
Process process = p.exec (command);
System.out.println ("The current operating system is:" + osname + "executed command:" + cmdstring);
}
}catch (Exception e) {
E.printstacktrace ();
}
}
/** test, can be ignored */
public static void Main (String agrs[]) {
Cmdcommand tmp = new Cmdcommand ();
Tmp.execcmd ("Nox.exe");
Tmp.execcmd ("Appium");
Tmp.execcmd ("Taskkill-f-pid Nox.exe");
Tmp.execcmd ("Taskkill-f-pid appium");
}
}
Java Exercise-004