Re: [go-nuts] Why do I get multiple times the same data?

133 views
Skip to first unread message

Martin Schnabel

unread,
Jul 29, 2021, 7:35:54 AM7/29/21
to hyogy hyogy, golang-nuts
hey,
your playground link does not compile! therefor you get a rot13 version
of the fixed playground link: uggcf://cynl.tbynat.bet/c/_wwLujQtms- ;)

Well who wants to be mean. Just move your buffer declaration into the
for loop or reset it: https://play.golang.org/p/hGovCri02lc

have fun

On 7/28/21 5:11 PM, hyogy hyogy wrote:
> I have recently added a ROT13 logic to a tool of mine.
> This tool connects to a server, from which I run commands on the client.
>
> Here is the code PRE-ROT13:
> https://play.golang.org/p/DAE4cLq3RSx
> Everything works like a charm.
>
> Here is the code POST-ROR13. The difference between them is underlined
> https://play.golang.org/p/DfFJSvuBx05
>
> Both functions handle the output of the commands.
> The ROT13 works fine, but I get the same output multiple time, which
> before did not happen. Infact, if I revert the changes, everything works
> perfectly.
> Example:
>
> */$ whoami/*
> */$ xnyv/*
> */
> /*
> */$ whoami/*
> */$ xnyv/*
> */xnyv/*
> */
> /*
> */$ whoami/*
> */$ xnyv/*
> */xnyv/*
> */xnyv/*
> */
> /*
> */$ whoami/*
> */$ xnyv/*
> */xnyv/*
> */xnyv/*
> */xnyv/*
>
> Why do I get this result? How can I fix it?
> May be fub's fault? It is like if the output get cached somehow, but I
> may be wrong.
>
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/3b3b8350-2251-4c71-8a95-8a84e4076e69n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/3b3b8350-2251-4c71-8a95-8a84e4076e69n%40googlegroups.com?utm_medium=email&utm_source=footer>.

hyogy hyogy

unread,
Jul 29, 2021, 2:41:21 PM7/29/21
to golang-nuts
I am more and more convinced that io.Copy(&fub, &q) is the problem

Il giorno mercoledì 28 luglio 2021 alle 17:11:40 UTC+2 hyogy hyogy ha scritto:
I have recently added a ROT13 logic to a tool of mine.
This tool connects to a server, from which I run commands on the client.

Here is the code PRE-ROT13:
Everything works like a charm.

Here is the code POST-ROR13. The difference between them is underlined

Both functions handle the output of the commands.
The ROT13 works fine, but I get the same output multiple time, which before did not happen. Infact, if I revert the changes, everything works perfectly.
Example:

$ whoami
$ xnyv

$ whoami
$ xnyv
xnyv

$ whoami
$ xnyv
xnyv
xnyv

$ whoami
$ xnyv
xnyv
xnyv
xnyv

Vadim Berezniker

unread,
Jul 30, 2021, 1:03:41 PM7/30/21
to hyogy hyogy, golang-nuts
fub is declared outside the for loop and io.Copy(&fub, &q) will append to the buffer. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/865969bf-d6e4-49ca-9ed5-809efae2f25cn%40googlegroups.com.
Message has been deleted

hyogy hyogy

unread,
Aug 18, 2021, 11:50:10 AM8/18/21
to golang-nuts
Thanks!(: Resetting the buffer was the solution! May I ask another tip please?
Reply all
Reply to author
Forward
0 new messages