drbuowqe02101 2019-07-17 13:31
浏览 70

Go工具中的命令行参数被忽略

I'm currently writing my first small tool in Go and I ran into the problem that no matter what I do, one command line argument is getting ignored.

mainFile := flag.String("input", "./generator.ini", "the input file")
outputFile := flag.String("foo", "Default directory foo bar blablabla", "the output directory")
fmt.Println("Param: ", *outputFile)
outputDir := filepath.Clean(*outputFile)

flag.Parse()

fmt.Println("Outputdir ", outputDir)
fmt.Println("Mainfile ", *mainFile)

So the thing is that outputFile is always the default value no matter how I call the programm.

.\generator.exe -input=D:\entwicklung\GoLang\src\github.com\Abenstex\CodeGenerator\generator\main.cfg -out=D:\entwicklung\test

It absolutely does not matter if -out comes before -input or not. The value of output is always the default whereas the input value is always correctly set. I'm really at a loss here.

  • 写回答

1条回答 默认 最新

  • dongshi9526 2019-07-17 13:41
    关注

    I found that I called flag.Parse() after I started using the parameter.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏