Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Do you know where your variables are?
 
PerlMonks  

my pipes

by Anonymous Monk
on Jul 23, 2001 at 09:36 UTC ( [id://98946]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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)

Replies are listed 'Best First'.
Re: my pipes
by mattr (Curate) on Jul 23, 2001 at 09:41 UTC
    Sorry this post was virtually unreadable. Could you repost as a reply, using <code> .. </code> please.
Re: my pipes
by bwana147 (Pilgrim) on Jul 23, 2001 at 09:47 UTC

    Please, please, use <code> tags so your code stands out as code. Still I tried and read your post, and it doesn't seem it can survive a use strict. So start by adding this on top of your code:

    #!/usr/local/bin/perl use strict; use warnings use diagnostics; ... your code here...
    When you're rid of all error messages, and your code still doesn't work as expected, then you can come back here.

    --bwana147

Re: my pipes
by wine (Scribe) on Jul 23, 2001 at 10:00 UTC
    Well, um, you're code looks horrible with a lot of bug and won't compile.

    I wonder why you want to use perl for this task. You don't really use the output or something. I'd use a shell script. For sh:

    #!/bin/sh # # some variations for executing 3 commands $1 ; $2 ; $3 # commands get executed after one another $1 && $2 && $3 # commands get only executed if previous succeeds $1 & $2 & $3 & # commands get forked # well you get the point, man sh for more ...

    - Good luck

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://98946]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.