I'm trying to execute a command using the command function but for some reasons I get this error very often ( not all the time)
c2 wait client 82.121.xxx.xxx, server xxx.xxx.x.xx, err signal: broken pipe
Executing from shell the command looks like this:
echo "password" | nmap -A tcp/443 --stdin -a $clientIP -D $serverIP -v
Below is what I have so far. Basically I run the first(at least that's what I think I'm doing) and provide the output as input for the 2nd command. Any idea what's wrong and how can I debug the issue?
c1 := exec.Command("echo", "password")
cmd2 := "nmap -A tcp/443 --stdin -a " + clientIP + " -D " + serverIP + " -v"
parts := strings.Fields(cmd2)
head := parts[0]
parts = parts[1:len(parts)]
c2 := exec.Command(head, parts...)
c2.Stdin, err = c1.StdoutPipe()
if err != nil {
log.Errorf("client %v, server %v, err %v",
clientIP, serverIP, err)
return err
}
c2.Stdout = os.Stdout
err = c2.Start()
if err != nil {
log.Errorf("c2 start client %v, server %v, err %v",
clientIP, serverIP, err)
}
err = c1.Run()
if err != nil {
log.Errorf("c1 start client %v, server %v, err %v",
clientIP, serverIP, err)
}
err = c2.Wait()
if err != nil {
log.Errorf("c2 wait client %v, server %v, err %v",
clientIP, serverIP, err)
return
}