Java Exercise-004

Source: Internet
Author: User
Tags appium

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.