src/os/proc.go
:
// Args hold the command-line arguments, starting with the program name.
var Args []string
func init() {
if runtime.GOOS == "windows" {
// Initialized in exec_windows.go.
return
}
Args = runtime_args()
}
When i debugged here,i found Args initialized before init function. Where does it initialied?
As the comment states: // Initialized in exec_windows.go.
src/os/exec_windows.go
:
func init() {
p := syscall.GetCommandLine()
cmd := syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(p))[:])
if len(cmd) == 0 {
arg0, _ := Executable()
Args = []string{arg0}
} else {
Args = commandLineToArgv(cmd)
}
}