duan1989643 2013-08-24 16:31
浏览 35
已采纳

在GO中调用外部命令

How can I call an external command in GO? I need to call an external program and wait for it to finish execution. before the next statement is executed.

  • 写回答

1条回答 默认 最新

  • dra11767 2013-08-24 16:34
    关注

    You need to use the exec package : start a command using Command and use Run to wait for completion.

    cmd := exec.Command("yourcommand", "some", "args")
    if err := cmd.Run(); err != nil { 
        fmt.Println("Error: ", err)
    }   
    

    If you just want to read the result, you may use Output instead of Run.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂