ric00015 has asked for the wisdom of the Perl Monks concerning the following question:
I am somewhat familiar with various ways of calling a script from another one. I don't really need an overview of each, but I do have a few questions. Before that, though, I should tell you what my goal is.
I am working on a perl/tk program that: a) gathers information and puts it in a hash, and b) fires off other scripts that use the info hash, and some command line args. Each of these other scripts are available on the command line (using another command-line script) and need to stay that way. So I can't just put all that into a module and call it good.I do have the authority to alter the scripts, but, again, they must also be usable on the command line.
The current way of calling the other script is by using 'do', which means I can pass in the hash, and use the same version of perl (I think). But all the STDOUT (and STDERR too, I think) goes to the terminal.
Here's a simple example to demonstrate the output:
this_thing.pl #!/usr/bin/env perl use strict; use warnings; use utf8; use Tk; my $mw = MainWindow->new; my $button = $mw->Button( -text => 'start other thing', -command => \&start, )->pack; my $text = $mw->Text()->pack; MainLoop; sub start { my $script_path = 'this_other_thing.pl'; if (not my $read = do $script_path) { warn "couldn't parse $script_path: $@" if $@; warn "couldn't do $script_path: $!" unless defined $read; warn "couldn't run $script_path" unless $read; } } this_other_thing.pl #!/usr/bin/env perl use strict; use warnings; use utf8; print "Hello World!\n";
How can I redirect the STDOUT and STDIN (for interactive scripts that need input) to the text box using the 'do' method? Is that even possible?
If I can't use the 'do' method, what method can redirect the STDIN and STDOUT, as well as enable passing the hash in and using the same version of perl?
Update! I talked with the one who originally created the scripts, and he agreed that jethro's suggestion of using modules and script wrappers was a good one. So that is what I am going to do. This ensures that I am not using different perls, I can route the output from the module anywhere I want, and passing that hash in is now very easy. Solves most, if not all, of my problems. Thanks, everyone, for your suggestions. See you around.
|
---|