douzhang6646 2019-01-29 10:20
浏览 200
已采纳

从shell脚本按Enter后读取GoLang命令行参数

So I am using a OSS written in go which I don't have any exposure to. I am trying to automate that script.

SO this is how the script works calling_go_code Message for confirmation of user Get user input execute the code.

I am trying to automate this script.

So far this is what I have tried, sh test.sh Param1

When I am running the script like

echo "hello"
calling_go_code

The above code asks for some parameter as input test.sh

sh test.sh Param1

echo "hello"
calling_go_code -- $1
  • 写回答

1条回答 默认 最新

  • dongyuyi5680 2019-01-30 08:07
    关注

    Based on @RichardHuxton's post. This is the solution I am using

    #!/usr/bin/expect -f
    
    
    set alias [lindex $argv 1]
    
    set input [lindex $argv 0]
    
    set timeout -1
    
    COMMAND I AM USING 
    
    expect {
    
        "*CONFIRMATION MESSAGE 1" { send -- $alias }
    
    
        exp_continue
    
    }
    
    
    expect {
    
        "*CONFIRMATION MESSAGE 2" { send -- $alias }
    
    
        exp_continue
    
    }
    
    expect eof
    

    Calling bot

     ./bot param1 param2
    

    Dependency of Expect

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

报告相同问题?

悬赏问题

  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载