exec.Command("telnet", ... ) failed with "exit status -1"

1,459 views
Skip to first unread message

平民四月份

unread,
Aug 15, 2012, 10:28:21 PM8/15/12
to golang-nuts, golang...@googlegroups.com
Hi all.
    I had used os/exec to run "telent" under window 7 64bit, it 's failed with error : "exit status -1", the source as follow, how can i solve it ?

import (
"bytes"
"fmt"
"os/exec"
)

func main() {

    var (
        cmd *exec.Cmd
        out bytes.Buffer
    )

    cmd = exec.Command("telnet", "163.com", "80")
    //cmd.Env = os.Environ()
    cmd.Stdout = &out
    if err := cmd.Run(); err != nil {
        fmt.Println(err)  //exit status -1
        return
    }
    fmt.Println(out.String())
}



--
 Face the sea, for the spring flowers blossoming




Scott Lawrence

unread,
Aug 15, 2012, 10:45:54 PM8/15/12
to 平民四月份, golan...@googlegroups.com
You should check to see if it prints anything to stderr.

Does telnet on windows require that stdout/stdin be a tty? Meaning, would the
following work:

$ telnet < instructions.txt > result.txt

?
> --
> Scott Lawrence
>
> go version go1.0.2
> Linux jagadai 3.4.8-1-ARCH #1 SMP PREEMPT Thu Aug 9 21:21:22 CEST 2012 x86_64
> GNU/Linux

--
Scott Lawrence

Zizon Qiu

unread,
Aug 15, 2012, 10:38:46 PM8/15/12
to 平民四月份, golang-nuts, golang...@googlegroups.com
Is telnet installed ?

tade....@gmail.com

unread,
Aug 14, 2014, 10:07:20 AM8/14/14
to golan...@googlegroups.com, golang...@googlegroups.com


May be you are missing straming mode setting on the remote machine where the telnet server is running on.

Enable the straming mode

  1. Logon to machine klpwpst01.klp.no and klpwpst02.klp.no
  2. Open a command prompt with Run as Administrator privilage.
  3. Run following command
tlntadmn config mode=stream

egon

unread,
Aug 14, 2014, 11:31:17 AM8/14/14
to golan...@googlegroups.com, golang...@googlegroups.com

This looks a very weird way to use telnet.

There are telnet packages available:

+ egon
Reply all
Reply to author
Forward
0 new messages