mirror of
https://gitlab.durp.info/durfy/modules/gopwsh.git
synced 2026-05-07 08:00:31 -05:00
initial commit
This commit is contained in:
parent
eb87a9c881
commit
6cdb3d2426
6 changed files with 377 additions and 0 deletions
45
powershell.go
Normal file
45
powershell.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue