mirror of
https://gitlab.durp.info/durfy/modules/gopwsh.git
synced 2026-05-07 16:10:29 -05:00
45 lines
629 B
Go
45 lines
629 B
Go
package gopwsh
|
|
|
|
type Powershell struct{}
|
|
|
|
func NewPowershellHandler() Powershell {
|
|
return Powershell{}
|
|
}
|
|
|
|
func RunPowershellCommand(cmd string) (string, error) {
|
|
|
|
ps := NewPowershellHandler()
|
|
shell, err := ps.New()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
defer shell.Exit()
|
|
|
|
sout, err := shell.Execute(cmd)
|
|
if err != nil {
|
|
return sout, err
|
|
}
|
|
|
|
return sout, nil
|
|
}
|
|
|
|
func (ps *Powershell) New() (Shell, error) {
|
|
|
|
handle, stdIn, stdOut, err := StartProcess(
|
|
"powershell.exe",
|
|
"-NoExit",
|
|
"-NoProfile",
|
|
"-Command",
|
|
"-",
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &shell{
|
|
handle,
|
|
stdIn,
|
|
stdOut,
|
|
}, nil
|
|
}
|