|
|
@ -0,0 +1,32 @@ |
|
|
|
package terminal |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"log" |
|
|
|
"os/exec" |
|
|
|
) |
|
|
|
|
|
|
|
/* 调用系统终端 */ |
|
|
|
func UseTerminal(name string, args ...string) map[string]interface{} { |
|
|
|
|
|
|
|
cmd := exec.Command(name, args...) |
|
|
|
|
|
|
|
var out bytes.Buffer |
|
|
|
|
|
|
|
mRet := make(map[string]interface{}) |
|
|
|
|
|
|
|
cmd.Stdout = &out |
|
|
|
err := cmd.Run() |
|
|
|
if err != nil { |
|
|
|
log.Println("ERROR", "140133|系统命令", name, args, "执行错误", err.Error()) |
|
|
|
mRet["ReturnCode"] = "140133" |
|
|
|
mRet["Msg"] = "系统终端命令执行出错" |
|
|
|
return mRet |
|
|
|
} |
|
|
|
|
|
|
|
mRet["ReturnCode"] = "1" |
|
|
|
mRet["Msg"] = "命令执行成功,获取输出成功" |
|
|
|
mRet["Result"] = out.String() |
|
|
|
return mRet |
|
|
|
|
|
|
|
} |