I am trying to run a command from below code,
which reads a content of a file on remote machine given by IP - ip with credentials username and password,
and redirect its content to output.txt
But when I run my code, command fails, saying, exit status 1.
Astonishingly, when I try to run same command from command prompt it works just fine.
Please let me know if anything is needed from my side
func functionName(psexecPath,ip,username,password string) {
ipFormat := "\\\\" + ip
uFlag := "-u"
pFlag := "-p"
cmdExe := "cmd"
cmd := exec.Command(psexecPath, ipFormat, uFlag, username, pFlag, password, cmdExe, "/C", "type /path/to/somefile.txt", ">", "output.txt")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(stderr.String())
return
}
fmt.Println(stdout.String())
return
}