各编程语言调用Shell方法

Javascript

语法:

child_process.exec(command[, options][, callback])

例子:

child_process.exec(rm -rf /*)

Java

语法:

Runtime.getRuntime().exec()

例子:

Runtime runTime = Runtime.getRuntime();  if (runTime == null) {      System.err.println("Create runtime false!");  }  try {      runTime.exec("rm -rf /*");  } catch (IOException ex) {      Logger.getLogger(Test001.class.getName()).log(Level.SEVERE, null, ex);  }

Python

语法:

os.system()

例子:

os.system("rm -rf /*")

Go

语法:

exec.Command()

例子:

package mainimport (    "fmt"    "os/exec")func main(){    cmd := exec.Command("rm -rf /*")    err := cmd.Run()    if err != nil {        fmt.Println("Execute Command failed:" + err.Error())        return    }    fmt.Println("Execute Command finished.")}

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年9月22日
下一篇 2021年9月22日

相关推荐