I've narrowed it down to a small section:

while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; } } else { last; } } continue { }

So, we skip empty lines; if we see "quit/exit", we close the socket, if we see "microsoft", we send a list of commands to the client, and that's where the problem crops up; I know it prints the whole list of commands to the client if the code is left like this, but I want the results of these commands, so I added:
while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; while( <$client> ) { print;} } } else { last; } } continue { }
Now, what happens is I get ALL the output from the first command I sent to $client, but the foreach loop is no longer able to iterate through all of "@commands" because I think it's hanging in the "while" loop. I have tried various things like putting "next;" after "print;", but I either get none of the command output, or I get what I want, but only for the first command, and then the client never closes it's connection (I send "exit" as the third command). I am trying to figure out if I'm just coming at this the wrong way (I have put various print statements within the top "while" loop, as well as trying to create an array to which all output would be stored, and then print the array:
while ( <$client> ) { while( my @response = <$client>) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; } print @client; } else { last; } } continue { } }
None of it is getting the results I want. #######################
Just in case anyone ever runs into this.. I figured it out:
... snip ... open(LOGFILE,>>"mylog.log") or die "Can't open mylog.log\n"; print $client "$cmds\r"; while( <$client> ) { print LOGFILE; } close $client; }
What I wanted to do was print commands to a netcat listener that was setup with "-e cmd.exe" (a la "reverse telnet") and capture all the output to a log file. Print commands to the socket, then do a "while( <$client>)". That seems to get the job done.

Good luck, and thanks for all the input.

In reply to Re^4: IO::Socket Bi-directional comm by carric
in thread IO::Socket Bi-directional comm by carric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.