STDOUT can not return to Screen
Posted
by rockyurock
on Stack Overflow
See other posts from Stack Overflow
or by rockyurock
Published on 2010-04-06T14:03:41Z
Indexed on
2010/04/06
14:13 UTC
Read the original article
Hit count: 289
perl
STDOUT can not return to Screen
Hello all
below is the part of my code, my code enters "if loop" with $value =1 and output of the process "iperf.exe" is getting into my_output.txt. As i am timing out the process after alram(20sec) time,also wanted to capture the output of this process only.
then after i want to continue to the command prompt but i am not able to return to the command promt...
not only this code itself does not PRINT on the command prompt , rather it is priniting on the my_output.txt file (i am looping this if loop through rest of my code)
output.txt
==========
inside value loop2
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 8.00 KByte (default)
------------------------------------------------------------
[160] local 10.232.62.151 port 5001 connected with 10.232.62.151 port 1505
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[160] 0.0- 5.0 sec 2.14 MBytes 3.59 Mbits/sec 0.000 ms 0/ 1528 (0%)
inside value loop3
clue1
clue2
inside value loop4
one iperf completed
Transfer
Transfer Starting: Intent { act=android.settings.APN_SETTINGS }
******AUTOMATION COMPLETED******
Looks some problem with reinitializing the STDOUT..
even i tried to use close(STDOUT); but again it did not return to STDOUT
could sombbody please help out ??
/rocky
CODE::
if($value)
{
my $file = 'my_output.txt';
use Win32::Process;
print"inside value loop\n";
# redirect stdout to a file
open STDOUT, '>', $file
or die "can't redirect STDOUT to <$file> $!";
Win32::Process::Create(my $ProcessObj,
"iperf.exe",
"iperf.exe -u -s -p 5001",
0,
NORMAL_PRIORITY_CLASS,
".") || die ErrorReport();
$alarm_time = $IPERF_RUN_TIME+2; #20sec
print"inside value loop2\n";
sleep $alarm_time;
$ProcessObj->Kill(0);
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
print"inside value loop3\n";
print"clue1\n";
#close(STDOUT);
print"clue2\n";
print"inside value loop4\n";
print"one iperf completed\n";
}
my $data_file="my_output.txt";
open(ROCK, $data_file)|| die("Could not open file!");
@raw_data=<ROCK>;
@COUNT_PS =split(/ /,$raw_data[7]);
my $LOOP_COUNT_PS_4 = $COUNT_PS[9];
my $LOOP_COUNT_PS_5 = $COUNT_PS[10];
print "$LOOP_COUNT_PS_4\n";
print "$LOOP_COUNT_PS_5\n";
my $tput_value = "$LOOP_COUNT_PS_4"." $LOOP_COUNT_PS_5";
print "$tput_value";
close(ROCK);
print FH1 "\n $count \| $tput_value \n";
regds rakesh
© Stack Overflow or respective owner