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 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测