process: add CmdlineSlice for darwin + windows
darwin will not perform correctly if there are spaces in the actual arguments, in which case a single argument will be reported as multple. Some CGO would be needed to get around this I think. I couldn't find any good documentation on how windows handles command line arguments with spaces inside the actual arguments, so this implementation merely just splits on spaces.
This commit is contained in:
parent
d098bf135f
commit
8c186ae593
|
@ -81,6 +81,9 @@ func (p *Process) Name() (string, error) {
|
|||
func (p *Process) Exe() (string, error) {
|
||||
return "", common.NotImplementedError
|
||||
}
|
||||
|
||||
// Cmdline returns the command line arguments of the process as a string with
|
||||
// each argument separated by 0x20 ascii character.
|
||||
func (p *Process) Cmdline() (string, error) {
|
||||
r, err := callPs("command", p.Pid, false)
|
||||
if err != nil {
|
||||
|
@ -88,8 +91,18 @@ func (p *Process) Cmdline() (string, error) {
|
|||
}
|
||||
return strings.Join(r[0], " "), err
|
||||
}
|
||||
|
||||
// CmdlineSlice returns the command line arguments of the process as a slice with each
|
||||
// element being an argument. Because of current deficiencies in the way that the command
|
||||
// line arguments are found, single arguments that have spaces in the will actually be
|
||||
// reported as two separate items. In order to do something better CGO would be needed
|
||||
// to use the native darwin functions.
|
||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||
return nil, common.NotImplementedError
|
||||
r, err := callPs("command", p.Pid, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r[0], err
|
||||
}
|
||||
func (p *Process) CreateTime() (int64, error) {
|
||||
return 0, common.NotImplementedError
|
||||
|
|
|
@ -5,6 +5,7 @@ package process
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
@ -144,9 +145,18 @@ func (p *Process) Cmdline() (string, error) {
|
|||
}
|
||||
return *dst[0].CommandLine, nil
|
||||
}
|
||||
|
||||
// CmdlineSlice returns the command line arguments of the process as a slice with each
|
||||
// element being an argument. This merely returns the CommandLine informations passed
|
||||
// to the process split on the 0x20 ASCII character.
|
||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||
return nil, common.NotImplementedError
|
||||
cmdline, err := p.Cmdline()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return strings.Split(cmdline, " "), nil
|
||||
}
|
||||
|
||||
func (p *Process) CreateTime() (int64, error) {
|
||||
dst, err := GetWin32Proc(p.Pid)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue