您的位置 首页 java

各编程语言调用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 (IO Exception  ex) {
      Logger.getLogger(Test001.class.getName()).log(Level.SEVERE, null, ex);
  }  

Python

语法:

 os.system()  

例子:

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

Go

语法:

 exec.Command()  

例子:

 package main

import (
    "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.")
}  

文章来源:智云一二三科技

文章标题:各编程语言调用Shell方法

文章地址:https://www.zhihuclub.com/188301.shtml

关于作者: 智云科技

热门文章

网站地图