Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by Corion (Patriarch) on Jan 07, 2013 at 18:04 UTC
|
select MYSTDOUT; # use *MYSTDOUT instead of STDOUT for output
# so all his reopening manipulates the wrong filehandle
# Run the original script in our interpreter
do 'original_script.pl' or die;
Update: Also, you should be able to combine this with davido's recommendation of Capture::Tiny to do the (re)capturing before the main script starts.
Update 2: No, it's unlikely. The Capture::Tiny documentation says:
Attempting to modify STDIN, STDOUT or STDERR during capture or tee is almost certainly going to cause problems. Don't do that. | [reply] [d/l] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by davido (Cardinal) on Jan 07, 2013 at 17:31 UTC
|
use Capture::Tiny qw( capture_stdout );
open STDOUT, '>/dev/tty' or die $!;
my $output = capture_stdout { print "Hello world!\n"; };
print "<<<$output>>>\n";
...the output...
<<<Hello world!
>>>
(as expected)
Update: ww has kindly reminded me that this is probably not a solution when you need to capture output of an external script. Apologies... and good luck! ;)
| [reply] [d/l] [select] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by salva (Canon) on Jan 07, 2013 at 21:09 UTC
|
You can use screen(1) to capture the output sent to /dev/tty easily. For instance:
$ screen -L ssh foo.bar.com
| [reply] [d/l] |
|
Sure, rub it in that we don't get to have screen at $work ;_;
You know I even tried ssh 0 cmd!! Using screen is a really cool idea though.
Originally I was just wondering if there was an obvious Perl solution to the problem that I was just either overlooking or of which I was unaware.
Tommy
"Perl follows the principle of least astonishment"
| [reply] [d/l] |
|
| [reply] [d/l] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by eyepopslikeamosquito (Archbishop) on Jan 07, 2013 at 18:05 UTC
|
| [reply] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by BrowserUk (Patriarch) on Jan 07, 2013 at 18:13 UTC
|
I'm not allowed to touch the script. That's completely forbidden.
Make your own local copy of the script, tweak and run that. The original is untouched.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
It communicates with a remote server to get the data it must process, and the remote server won't communicate with the script unless it has the right crypto hash...
I decided the rabbit hole was getting too deep, and I wrote my own version in 1 line of shell code (a very long line with lots of pipes and regexen). *sigh*... Sometimes to win, you just have to know when you're beaten.
Tommy
"Perl follows the principle of least astonishment"
| [reply] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by clueless newbie (Curate) on Jan 07, 2013 at 20:14 UTC
|
Being just a clueless newbie, I'd create a simple module (call it MyOpen) that overrides CORE::open. Upon encountering a '/dev/tty' it can then substitute '/dev/null' or something more appropriate before calling CORE::open. Pack this into the invoking system / backticks using -MMyOpen. or set PERL5OPT.
| [reply] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by dbuckhal (Chaplain) on Jan 07, 2013 at 21:56 UTC
|
How about using shell redirection?
$ script.pl >> output.txt
Otherwise, maybe you can present a case of your desired changes you would like to make to that file and seek approval. I can't imagine any piece of software being completely forbidden forever! heh | [reply] [d/l] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by bart (Canon) on Jan 09, 2013 at 14:49 UTC
|
| [reply] |
Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
by pvaldes (Chaplain) on Jan 08, 2013 at 21:44 UTC
|
| [reply] [d/l] [select] |