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.


In reply to I want to run a script from another script, use the same version of perl, and reroute IO to a terminal-like textbox by ric00015

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.