in reply to Re: How to capture process and redirect STDOUT in a hash
in thread How to capture process and redirect STDOUT in a hash
Hello graff,
Thank you for your time and effort reading and replying to my question. I was reading about that too, and actually I have manage to create a solution that writes the data into a file and then I open that file and process the data according to my needs.
What I was hopping to achieve is to avoid opening this file read, open another file process the data and write. I was hoping that there is a way to capture the STDOUT and process it before is stored to the file.
The way that easily can be done to write to the file is through the parameters that you set at the beginning. I am posting the solution just in case someone in the future might be interested on that.
Sample of code is provided under:
open my $stdout_fh, '>>', 'test.log' or die $!; foreach my $hash ( @mps ) { $pssh->add_host( $ini{$hash}{host} , user => $ini{$hash}{user}, port => $ini{$hash}{port}, password => $ini{$hash}{psw}, default_stdout_fh => $stdout_fh ); }
It also possible to store the STDOUT to different file(s). It could be extremely easy just by adding another parameter into my conf.ini file and add a hash value on the foreach loop where you add the devices to prove. By doing that you can have different STDOUT on different device(s). Of Course by doing that you also need to add an open file process with the hash on the same foreach loop. Final step at the end of the process after write you need to close the files with a loop again.
It might sound complicated but in reality is extremely simple.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to capture process and redirect STDOUT in a hash
by graff (Chancellor) on Jan 02, 2015 at 18:17 UTC |