doudun2212 2016-04-26 10:40
浏览 40
已采纳

os.Args仅读取在golang中运行文件时提供的一些数据[重复]

This question already has an answer here:

My Program:

package main

import (
    "log"
    "os"
)

func main() {
    inputs := os.Args[1:]
    log.Print(inputs)
}

When run with the command

go run filename.go 3001-3005 1->A,2->B,3->C,4->D,5->E

gives the output as [3001-3005 1-,2-,3-,4-,5-] instead of [3001-3005 1->A,2->B,3->C,4->D,5->E]

</div>
  • 写回答

1条回答 默认 最新

  • dsgnze6572 2016-04-26 10:55
    关注

    The ">" characters on your command line are being interpreted as redirections meaning "send output to a file rather than to the console".

    You should be able to stop this happening by quoting the command-line arguments in question. Exactly how you should do this depends on what OS you're on, what shell you're using if you're on a Unix-like OS, etc, but I would try putting double-quotes around that second argument, like this:

    go run filename.go 3001-3005 "1->A,2->B,3->C,4->D,5->E"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程