GoTerpsGo has asked for the wisdom of the Perl Monks concerning the following question:

I've been tasked to create a quick little Perl script to monitor the output from a Cisco router's serial port and to print it out to STDOUT. I want to have the output be flushed to STDOUT at every newline. I discovered today Cisco (at least for IOS v12.4) uses CRLF (\x0A \x0D) for their newlines. I thought I could just have my code say:

$objPort = new Win32::SerialPort...; $objPort->are_match("\n", "\r\n"); $foo = $objPort->lookfor;

I ran the script during the router's bootup; it only picked up 4 lines or so while skipping the rest of the others. I've searched online but most of the stuff was about stripping newlines from serial streams. Has anyone else tried this before? Thx for your attention.

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: Need help with Win32::SerialPort
by TGI (Parson) on Jun 09, 2007 at 17:51 UTC
    As anonymonk puts it, "loop":
    while( $run ) { my $newline = $objPort->lookfor; if ( $newline ne '' ) { print $newline; $run = 0 if $newline =~ /reason to stop/; } }

    Another possibility is that your are_match() settings are matching "\n" and leaving "\r" on your lines, so when then print to the terminal, each line of text is overwritten. Try directing the output to file. That should show you if this is happening.

    Also, be careful with "\n", because it can mean "\r\n" in some windows perl environments. You should consider using the hexadecimal escapes "\x0A" and "\x0D", as no magic happens with them.

    Update: Fixed escape sequences. Thanks to BrowserUk.


    TGI says moo

      Arrrrrrgh.... I apparently did everything you already suggested except for one thing - I used != instead of ne. Damnit... Thx for the help.
A reply falls below the community's threshold of quality. You may see it by logging in.