summaryrefslogtreecommitdiff
path: root/src/pkg/os/exec_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/os/exec_windows.go')
-rw-r--r--src/pkg/os/exec_windows.go39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/pkg/os/exec_windows.go b/src/pkg/os/exec_windows.go
index 65e94ac4a..7eb7d194d 100644
--- a/src/pkg/os/exec_windows.go
+++ b/src/pkg/os/exec_windows.go
@@ -5,11 +5,15 @@
package os
import (
+ "errors"
"runtime"
"syscall"
+ "unsafe"
)
-func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
+// Wait waits for the Process to exit or stop, and then returns a
+// Waitmsg describing its status and an error, if any.
+func (p *Process) Wait(options int) (w *Waitmsg, err error) {
s, e := syscall.WaitForSingleObject(syscall.Handle(p.handle), syscall.INFINITE)
switch s {
case syscall.WAIT_OBJECT_0:
@@ -17,11 +21,11 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
case syscall.WAIT_FAILED:
return nil, NewSyscallError("WaitForSingleObject", e)
default:
- return nil, NewError("os: unexpected result from WaitForSingleObject")
+ return nil, errors.New("os: unexpected result from WaitForSingleObject")
}
var ec uint32
e = syscall.GetExitCodeProcess(syscall.Handle(p.handle), &ec)
- if e != 0 {
+ if e != nil {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
p.done = true
@@ -29,24 +33,25 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
}
// Signal sends a signal to the Process.
-func (p *Process) Signal(sig Signal) Error {
+func (p *Process) Signal(sig Signal) error {
if p.done {
- return NewError("os: process already finished")
+ return errors.New("os: process already finished")
}
switch sig.(UnixSignal) {
case SIGKILL:
e := syscall.TerminateProcess(syscall.Handle(p.handle), 1)
return NewSyscallError("TerminateProcess", e)
}
- return Errno(syscall.EWINDOWS)
+ return syscall.Errno(syscall.EWINDOWS)
}
-func (p *Process) Release() Error {
+// Release releases any resources associated with the Process.
+func (p *Process) Release() error {
if p.handle == -1 {
return EINVAL
}
e := syscall.CloseHandle(syscall.Handle(p.handle))
- if e != 0 {
+ if e != nil {
return NewSyscallError("CloseHandle", e)
}
p.handle = -1
@@ -55,12 +60,26 @@ func (p *Process) Release() Error {
return nil
}
-func FindProcess(pid int) (p *Process, err Error) {
+func findProcess(pid int) (p *Process, err error) {
const da = syscall.STANDARD_RIGHTS_READ |
syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
h, e := syscall.OpenProcess(da, false, uint32(pid))
- if e != 0 {
+ if e != nil {
return nil, NewSyscallError("OpenProcess", e)
}
return newProcess(pid, int(h)), nil
}
+
+func init() {
+ var argc int32
+ cmd := syscall.GetCommandLine()
+ argv, e := syscall.CommandLineToArgv(cmd, &argc)
+ if e != nil {
+ return
+ }
+ defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv))))
+ Args = make([]string, argc)
+ for i, v := range (*argv)[:argc] {
+ Args[i] = string(syscall.UTF16ToString((*v)[:]))
+ }
+}