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()
}
当我在这里调试时,我发现Args在初始化函数之前已初始化。在哪里初始化?
答案 0 :(得分:1)
如评论所述:// 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)
}
}