Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Threads Printing Issue - Output Mangled / Term Crashing

by BrowserUk (Pope)
on Apr 14, 2014 at 09:24 UTC ( #1082207=note: print w/ replies, xml ) Need Help??


in reply to Threads Printing Issue - Output Mangled / Term Crashing

You appear to be outputting linefeeds but not carriage returns.

Fix that and your problem will go away.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Threads Printing Issue - Output Mangled / Term Crashing
Re^2: Threads Printing Issue - Output Mangled / Term Crashing
by bigbot (Beadle) on Apr 14, 2014 at 11:05 UTC

    Thanks for the reply Browser. I understand what you're saying, but these results don't make sense to me.

    I can simply print "TEST\n" on that line and it will still have the output formatting issue. I use this type of print in many scripts, and have never seen it destroy the terminal or mangle output. Since I'm using Linux, why is a carriage return required?

    Also, the issue only presents itself when the SSH/tcpdump line is included. The results of that line are currently put into a variable which isn't even being printed out.

    Thanks

      Since I'm using Linux, why is a carriage return required?

      (Note: most of this is guesswork regarding *nix -- not my FOE -- but its nothing to do with threads)

      In the days of old, the linefeed character just moved to the next line; an carriage return was required to move to the start of the line. (Think about how manual typewriters operate. If you ever seen one.)

      To the best of my knowledge, most *nix consoles only require LF to cause them to perform both operations, but that's a reinterpretation of the purpose, and probably only operates when the console is operating in 'cooked' mode.

      My guess is that

      the issue only presents itself when the SSH/tcpdump line is included.

      the command you are issuing is switching the terminal into 'raw' (or 'ultra-raw') mode and failing to reset it when it ends. Hence, thereafter, the LF is only moving to the next line, and is failing to return to the left hand edge.

      Perhaps the thing to do is use Term::ReadKey::ReadMode() to control/restore the settings after the command ends.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        That makes sense. I'm no way any expert on Linux Terminals and this is a weird issue I haven't seen before. Once I get back to work on Wednesday I'll troubleshoot this some more. Thank you again.

        One other question: My ultimate goal is to use pipe opens in the threads if possible. Currently I'm capturing only 10 packets into those scalars. I would much rather prefer to use the pipe opens (so that data is continuously streamed from the various servers and printed out in real time). I had some trouble trying to implement that however. What would you recommend to perform such a task? Basically the code was the same, but the SSH line was replaced with a pipe open to the SSH/tcpdump process, then a while loop in each thread, that would print data if it was seen.

        I can see that being difficult, as I've read in a few places that pipe opens aren't supported in Perl threads. Still, it would be much more preferable to find a way to stream the data continuously and not just capture 10 packets at a time, having to run the entire thing in some loop that constantly creates new SSH connections.

      compare stty Settings before and after. Probably something with opost, ocrnl, or some such Parameter.
        Good idea I'll definitely do that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082207]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-07-29 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls