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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失