1.2获取命令行参数

package main

import (
	"fmt"
	"os"
)

func main() {
	args := os.Args

	// all command line args
	println(args)

	// The first argument, zero item from array,
	// is the name of the called binary.
	programName := args[0]
	fmt.Printf("The binary name is: %s \n", programName)

	// by omiting the first argument.
	otherArgs := args[1:]
	fmt.Println(otherArgs)

	for idx, arg := range otherArgs {
		fmt.Printf("Arg %d = %s \n", idx, arg)
	}

}

/*
[5/5]0xc42000e140
The binary name is: ./go_web 
[fdsf fdsaf dsafdsfkf 1234]
Arg 0 = fdsf 
Arg 1 = fdsaf 
Arg 2 = dsafdsfkf 
Arg 3 = 1234 

*/

posted on 2018-03-17 21:41  cucy_to  阅读(130)  评论(0编辑  收藏  举报

导航