1 回答

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊
試試這個(gè),它還可以讓你看到發(fā)送到 stderr 的輸出。詳情在這里。
具體來(lái)說,就您而言,問題在于
'pwd' is not recognized as an internal or external command,
operable program or batch file.
package main
import (
"fmt"
"log"
"os/exec"
"os"
)
func execute_this(cmd string ) string {
c := exec.Command("cmd","/C", cmd)
c.Stderr = os.Stderr
out, err := c.Output()
if err != nil {
log.Fatal(err)
}
return string(out)
}
func main() {
cmd := "pwd"
result := execute_this(cmd)
fmt.Println(result)
}
- 1 回答
- 0 關(guān)注
- 105 瀏覽
添加回答
舉報(bào)