Hi All, I am a long term on-and-off programmer but new to Perl. I pinched this spawn_server/spawn_client example off the net because I need to pass a process that is waiting for more input back from a module. This example seemed to provide the pieces I need. As it stands, it works on my (Windows) box. All I had to do to make it work was change the process call paths. But when I make the substitutions in the "Changed" sections to use IO::File - so that I can pass the process' STDIN around between subs - it doesn't work. Obviously I am misunderstanding the relationship between normal handles and IO::File. Can anyone point me in the right direction? I have read (several times) tutorials on the net about passing references but only including the entries in the name table that are file handles - I tried, but that had me lost. IO::File looked a lot simpler :-)

use Win32::Process; # First file spawn_server.pl #===================== V Added 1 V ============================== use IO::File ; my $savein = new IO::File ; #===================== A Added 1 A ============================== %Data = ( one =>1, two =>2, three =>3 ); pipe(READ, WRITE); select(WRITE); $| = 1; select(STDOUT); #===================== V Changed 1 V ============================== += #$savein->open ( "< &STDIN" ) || die "Can not save STDIN\n"; open(SAVEIN, "< &STDIN") || die "Can not save STDIN\n"; #===================== A Changed 1 A ============================== += open(STDIN, "< &READ") || die "Can not redirect STDIN\n"; select(STDIN); $| = 1; select(STDOUT); Win32::Process::Create ( $Proces , "c:\\perl\\bin\\perl.exe", "c:\\perl\\bin\\perl.exe c:\\ +db2maint\\cmd\\perl\\spawn_client.pl", 1 , NORMAL_PRIORITY_CLASS , "c:\\db2maint\\test" ); #===================== V Changed 2 V ============================== += #open(STDIN, "< &savein"); open(STDIN, "< &SAVEIN"); #$savein->close () ; close(SAVEIN); #===================== A Changed 2 A ============================== += close(READ); print "$0: Sending variables to child...\n"; foreach $Temp (keys(%Data)){ print "$0:\t$Temp=$Data{$Temp}\n"; print WRITE "\$Data{$Temp}=$Data{$Temp};\n"; } print "$0: Finished sending variables.\n"; close(WRITE); print "$0: About to terminate. Waiting for <RETURN> to be hit...\n"; <STDIN>; print "$0: End.\n";
# Separate file - spawn client. print "$0: Starting.\n"; print "$0: Reading in variables...\n"; while(<STDIN>){ eval($_); print "$0: \t$_"; } print "$0: Finished reading variables.\n"; print "$0: Dumping variables...\n"; foreach $Temp (keys(%Data)){ print "$0:\t$Temp=$Data{$Temp}\n"; } print "$0: End.\n";

Note, both files do run with the substitutions in place but nothing seems to get passed to the client.


In reply to How do you redirect STDIN using IO::File ? by malJam

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.