i have written this program and would like to adapt it so that it would accept 1 to 3 commands and not just 3. and execute the commands if anyone could help it would be most appreciated.
#!/usr/local/bin/perl -w pipe PIPEIN1,PIPEOUT1;#pipe1 pipe PIPEIN2,PIPEOUT2;#pipe2 $command1=<STDIN>; # read command 1 from user chomp($command1); # remove new line character $command2=<STDIN>; # read command 2 from user chomp($command2); # remove new line character $command3=<STDIN>; # read command 3 from user chomp($command3); # remove new line character if (fork ==0)#child 1 { close PIPEIN1; # close pipe in 1 close PIPEIN2; # close pipe in 2 close PIPEOUT2; # close pipe out 2 close STDOUT; # close standard out open STDOUT, ">&PIPEOUT1"; #open standard out and pipe1 exec $command1; } if (fork==0)#child 2 { close PIPEIN2; #close pipe in 2 close PIPEOUT1; # close pipe out 1 close STDIN; # close standard in open STDIN, "<&PIPEIN1";# open standard in and pipe1 close STDOUT; # close standard out open STDOUT, ">&PIPEOUT2";# open standard out and pipe 2 exec $command2; } if (fork==0)#child 3 { close PIPEIN1; # close pipe in 1 close PIPEOUT1; # close pipe out 1 close PIPEOUT2; # close pipe out 2 close STDIN; # close standard in open STDIN, "<&PIPEIN2"; # open standard in and pipe in 2 exec $command3; } close PIPEIN1; # close pipe in 1 close PIPEOUT1; # close pipe out 1 close PIPEIN2; # close pipe in 2 close PIPEOUT2; # close pipe out 2 wait; # wait for child 1 to terminate wait; # wait for child 2 to terminate wait; # wait for child 3 to terminate

Edit - Masem added code tags
Edit - ar0n More descriptive title


In reply to Forking Multiple Children by Anonymous Monk

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.