0

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
}
Anthony Hunt
  • 1,470
  • 5
  • 20
  • 32
  • possible duplicate of [How to pipe several commands?](http://stackoverflow.com/questions/10781516/how-to-pipe-several-commands) – OneOfOne Oct 05 '14 at 02:53
  • Euuuh, are you able to run that nmap command in the commandline, because I am not. – RickyA Oct 07 '14 at 15:08
  • Ubuntu 12.04: `Illegal netmask value, must be /0 - /32 . Assuming /32 (one host)` ; `Failed to resolve given hostname/IP: tcp. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges` ; `nmap: option '-a' is ambiguous; possibilities: '--append_output' '--adler32' '--allports' '--append-output'` – RickyA Oct 07 '14 at 15:10
  • @RickyA actually "nmap" is a placeholder... I'm running something else and the command works most of the time, still I'm wondering what broken pipe really means as I don't get any error back(unless the program itself errors out). – Anthony Hunt Oct 07 '14 at 18:56
  • 1
    Well, without the actual command we can't really do anything here, but if you are looking for the cause of broken pipes then [this](http://unix.stackexchange.com/questions/84813/what-makes-a-unix-process-die-with-broken-pipe) has a nice answer. – RickyA Oct 10 '14 at 08:35
  • Thanks Ricky! that's the answer I was looking for...now I have to figure it out why Go gets in the loop of broken pipes. The real issue is that once the pipe breaks once it keeps breaking until I restart the app. – Anthony Hunt Oct 11 '14 at 15:17

0 Answers0