CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Flush file handler without print its content

 



kazerm
New User

Jun 23, 2009, 11:41 PM

Post #1 of 5 (2191 views)
Flush file handler without print its content Can't Post

Is there a way to flush a filehandler in perl without print it?

I'm using open inside of fork command inside foreach command:
foreach (){
fork(){
open ($cmd |);
}
}
and if I'm printing the filehandler content - the script waits till the $cmd ends before it start an new loop (of the foreach) - I want to avoid this - I need to fork the commands one after the another without waiting, but if I'm not printing the filehandler content - the buffer is getting full and the program get stuck.

Any idea how to solve this?

Thanks


KevinR
Veteran


Jun 24, 2009, 12:31 AM

Post #2 of 5 (2190 views)
Re: [kazerm] Flush file handler without print its content [In reply to] Can't Post

to flush the buffer you can try:


Code
$|++;


or:


Code
$| = 1;


from perlvar:

# HANDLE->autoflush(EXPR)
# $OUTPUT_AUTOFLUSH
# $|

If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See getc for that. (Mnemonic: when you want your pipes to be piping hot.)
-------------------------------------------------


kazerm
New User

Jun 24, 2009, 1:12 AM

Post #3 of 5 (2188 views)
Re: [KevinR] Flush file handler without print its content [In reply to] Can't Post

Thanks for the replay - but it didn't help (I already tried it)

The prgram still get stuck, the only way that it doesn't is when i'm doing:

my @arr = <FILEHANDLER>;

But again, this way the program is waiting till the command will finish (and yes, the command ssh from linux to windows and run another command there)


1arryb
User

Jun 24, 2009, 7:50 AM

Post #4 of 5 (2183 views)
Re: [kazerm] Flush file handler without print its content [In reply to] Can't Post

Hi kazerm,

This may help: http://www.wellho.net/solutions/perl-controlling-multiple-asynchronous-processes-in-perl.html.

Good luck,

Larry


KevinR
Veteran


Jun 24, 2009, 12:38 PM

Post #5 of 5 (2180 views)
Re: [1arryb] Flush file handler without print its content [In reply to] Can't Post


In Reply To


Very cool, a link to wellho.net. Graham Ellis is a great guy.

http://www.wellho.net/horse/
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives