iam trying to create a program which will accept up to three commands pipe them and execute them. so far my program keeps crashing any help would be appreciated below is my program:
#!/usr/local/bin/perl -w # perl script to pipe up to 3 commands together $cmd=<STDIN>; #get input chomp($cmd); #remove carriage return @cmd=split(#,$cmd); #seperate commands by a # $max=3; #set max size of array to 3 $max=@cmd; #assign size to array cmd $max=$max-1; #let the array start at 0 for($x=1;$x<$max-1;$x++){ #go through each element of the array if(fork==0) { #do the first command for($n=1;$n<$max-1;$n++) #close all input pipes close INPIPE[$n]; for($p=2;$p<$max-1$p++) #close all the output pipes close OUTPIPE[$p]; #except the last one close STDOUT; open STDOUT">&OUTPIPE[1]"; #first output pipe still open exec cmd[1];#execute the first command } elseif (x=max-1) #second command { for($n=1;$n<max-1;$n++) #close all input pipes if n!=x-1 close INPIPE[$n]; if n!=x-1 close OUTPIPE[$n]; #close outpipe close STDIN; #close STDIN open STDIN">&INPIPE[n-1]; close STDOUT; #close STDOUT open STDOUT">&OUTPIPE[n]; exec cmd[2]; } elseif(x=max) #last command for($n=1;$n<max-2;$n++) #close all input pipes Close INPIPE[$n]; for($p=1;$p<$max-1;$p++) #close all output pipes close INPIPE[$p]; #close INPIPE close STDIN; open STDIN">&INPIPE[max]; exec cmd[3]; #execute the last command } } for($d=1; $d<$max-1; $d++) { close INPIPE[$d]; #close INPIPES close OUTPIPE[$d]; #close outpipes } for($s=1;$s<$max-1;$s++) { wait; # wait for the child process } {

Edit Masem - 2001-07-24 - Added CODE tags (sic)


In reply to my pipes 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.