down123321123 2018-10-31 12:49
浏览 83

如何为通过go脚本运行的终端命令提供选项?

Lets suppose I have a go script which invokes the command

yum install packagename.

It comes to a point where it asks y/n to install the package, there is --assumeyes option in yum (in this case) which i dont want to use.

Is there any other way in go to send y to the command as i dont want to give the y manually when running the script

  • 写回答

1条回答

  • duandang9434 2018-10-31 13:06
    关注

    The y is inputted via stdin. When you launch a subprocess, you give it a writer where you can write to its stdin.

    The os/exec docs have an example.

    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝