golang 执行php
golang 执行php
linux
jsons:=`'{"contact": "contac2t", "tel": "tel2","email": "email12","addr": "add4r","id":"1652067182000000076"}'` str:=fmt.Sprintf("php "+"a.php '"+jsons+"'") cm:=ex ec.Command("/bin/bash","-c",str) stdout0 , err := cm.StdoutPipe() // 获取命令输出内容 if err != nil { fmt.Println(err) return }else{ fmt.Println(stdout0) } if err := cm.Start(); err != nil { //开始执行命令 fmt.Println(err) return } if opBytes, err := ioutil.ReadAll(stdout0); err != nil { // 读取输出结果 log.Fatal(err) } else { fmt.Println(string(opBytes)) }
win
jsons:=`'{"contact": "contac2t", "tel": "tel2","email": "email12","addr": "add4r","id":"1652067182000000076"}'` str:=fmt.Sprintf("php "+"a.php '"+jsons+"'") //cm :=ex ec.Command("cm d.exe","/c",str) cm =exec.Command("C:/Program Files/Git/bin/bash","-c",str) win使用git stdout0 , err := cm.StdoutPipe() // 获取命令输出内容 if err != nil { fmt.Println(err) return }else{ fmt.Println(stdout0) } if err := cm.Start(); err != nil { //开始执行命令 fmt.Println(err) return } if opBytes, err := ioutil.ReadAll(stdout0); err != nil { // 读取输出结果 log.Fatal(err) } else { log.Println(string(opBytes)) fmt.Println(string(opBytes)) }
php接受参数
function test($argv){ $param=json_decode($argv[1]); echo json_encode($param); } test($argv);