PacketSender icon indicating copy to clipboard operation
PacketSender copied to clipboard

processing windows console output by FOR loop

Open lazna opened this issue 9 years ago • 8 comments

Trying to process program console version by windows internal FOR loop (using -w 30000 option), but seems FOR loop eat whole data after program finish. What method did you use to print output? As far as I am not a programmer, there could be at least two methods how to print out console program output: Print whole data after program finish, or print data line-by-line as program generate them.

Writing script to detecting reachable network devices which respond to broadcast and it will be helpfull if I can see rapidly answering devices immediatelly to start working with them, and later respond devices when come back to console window. It will save time...

lazna avatar Jul 24 '16 19:07 lazna

Maybe you could redirect output to a file...

Example: packetsender --version > myfile.txt

I think the file write happens even if it hasn't finished yet. Then you can watch that file somehow.

dannagle avatar Jul 24 '16 20:07 dannagle

I can see this, but I want to avoid periodical disc writes in my system (small SSD is used, script will be started each 5 minutes and other good reasons). Is it possible to program print every packets to STDOUT when it arrive, not when '-w' timed out and program terminate?

lazna avatar Jul 27 '16 18:07 lazna

I am printing to STDOUT whenever a packet arrives:

QTextStream out(stdout);


            if(quiet) {
                out << "\n" << hexString;

            } else {
                out << "\nResponse Time:" << QDateTime::currentDateTime().toString(DATETIMEFORMAT);
                out << "\nResponse HEX:" << hexString;
                out << "\nResponse ASCII:" << Packet::hexToASCII(hexString);
            }

            out.flush();
            QCoreApplication::flush();

dannagle avatar Jul 27 '16 18:07 dannagle

As I am telling you, I am not a programmer, have some (maybe dumb) ideas.

What about EOL characters? Or do you have any other idea?

BTW: I am asking in cmd.exe newsgroup for the FOR loop standard behaviour too.....

lazna avatar Jul 27 '16 18:07 lazna

Do you mind posting your for loop here? Maybe I can see what is happening.

dannagle avatar Jul 27 '16 19:07 dannagle

for /f "tokens=*" %a in ('packetsender -uw 5000 255.255.255.255 10001 "01 00 00 00"') do echo %a

lazna avatar Jul 27 '16 19:07 lazna

I've never used Batch beyond anything really basic, but it looks like you are echoing out a variable after the loop is finished. That's why the print happens at the end. You may need additional print statements as you are saving the results to the variable if you want to see them immediately.

If you are trying to do some complicated parsing, you may prefer the -q (quiet) option when you send your broadcast.

dannagle avatar Jul 27 '16 20:07 dannagle

As far as I knew batch files working, it took input line by line, parse it and process 'do' sequence on it. Why in some cases wait till input program terminate in mystery for me.

lazna avatar Jul 27 '16 21:07 lazna