go - Runtime Error: Index out of range when attempting to os.StartProcess -
i can't seem figure out why it's doing this:
i have function setup this:
func (srv *server) startserver() { // stuff make sure paths correct path := srv.path + "server.exe" var args = []string{ "ip=" + srv.ip, "un=" + srv.username, "pw=" + srv.password } proc, err := os.startprocess(path, args, new(os.procattr)) if err != nil { panic(err) } }
the startprocess method throws index out of range.
i'm missing something, can't see it.
exact error requested:
panic: runtime error: index out of range goroutine 1 [running]: syscall.startprocess(0xc082052b70, 0x21, 0xc08200a6e0, 0x5, 0x5, 0xc08201dd60, 0x0, 0x0, 0x0, 0x0) c:/go/src/syscall/exec_windows.go:322 +0x94c os.startprocess(0xc082052b70, 0x21, 0xc08200a6e0, 0x5, 0x5, 0xc08200a730, 0x5217e0, 0x0, 0x0) c:/go/src/os/exec_posix.go:45 +0x482 os.startprocess(0xc082052b70, 0x21, 0xc08200a6e0, 0x5, 0x5, 0xc08200a730, 0x0, 0x0, 0x0) c:/go/src/os/doc.go:24 +0x79 main.(*server).startserver(0x5efae0) e:/build_test/srvmgr.go:85 +0x4e6 main.main() e:/build_test/srvmgr.go:54 +0x141 goroutine 2 [runnable]: runtime.forcegchelper() c:/go/src/runtime/proc.go:90 runtime.goexit() c:/go/src/runtime/asm_amd64.s:2232 +0x1 goroutine 3 [runnable]: runtime.bgsweep() c:/go/src/runtime/mgc0.go:82 runtime.goexit() c:/go/src/runtime/asm_amd64.s:2232 +0x1 goroutine 4 [runnable]: runtime.runfinq() c:/go/src/runtime/malloc.go:712 runtime.goexit() c:/go/src/runtime/asm_amd64.s:2232 +0x1 exit status 2
edit: link simplified play.golang post reproducing it. i'm running go version 1.4.2 win/amd64
you getting error because not set file descriptors stderr , stdout on os.procattr. seems set automatically on linux, need set them on windows.
this working example:
func (srv *server) startserver() { // stuff make sure paths correct path := srv.path + "server.exe" var args = []string{ "ip=" + srv.ip, "un=" + srv.username, "pw=" + srv.password } var attr os.procattr attr.files = []*os.file{nil, os.stdout, os.stderr} proc, err := os.startprocess(path, args, &attr) if err != nil { panic(err) } }
Comments
Post a Comment