[Bio] / FortyEight / JobStage.pm Repository:
ViewVC logotype

Diff of /FortyEight/JobStage.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Thu Sep 13 19:56:18 2007 UTC revision 1.3, Wed Jun 11 21:19:16 2008 UTC
# Line 151  Line 151 
151          print "$msg\n";          print "$msg\n";
152          $self->fatal($msg);          $self->fatal($msg);
153      }      }
154        close($errfh);
155        $self->log("process $cmd finishes successfully");
156    }
157    
158    =head3 run_process_nofatal($tag, $cmd, @args)
159    
160    Run the given command and argument list in a subshell. Stdout and stderr are collected
161    and written to jobdir/errors/$tag.stderr.
162    
163    If the command fails, this code invokes die.
164    
165    =cut
166    
167    sub run_process_nofatal
168    {
169        my($self, $tag, $cmd, @args) = @_;
170    
171        -x $cmd or die("run_process: command $cmd is not executable");
172    
173        $self->log("running $cmd @args");
174    
175        my $pid = open(P, "-|");
176        $self->log("created child $pid");
177    
178        if ($pid == 0)
179        {
180            open(STDERR, ">&STDOUT");
181            exec($cmd, @args);
182            die "Cmd failed: $!\n";
183        }
184    
185        my $errfh = $self->open_error_file($tag, "w");
186        $errfh->autoflush(1);
187    
188        while (<P>)
189        {
190            print $errfh $_;
191            print "$tag: $_";
192        }
193    
194        if (!close(P))
195        {
196            my $msg = "error closing $tag pipe: \$?=$? \$!=$!";
197            print $errfh "$msg\n";
198            close($errfh);
199            print "$msg\n";
200            die($msg);
201        }
202        close($errfh);
203        $self->log("process $cmd finishes successfully");
204    }
205    
206    sub run_process_in_shell
207    {
208        my($self, $tag, $cmd) = @_;
209    
210        $self->log("running $cmd");
211    
212        my $pid = open(P, "$cmd |");
213        if (!defined($pid))
214        {
215            $self->fatal("run_process_in_shell(): error creating pipe from $cmd: $!");
216        }
217    
218        $self->log("created child $pid");
219    
220        my $errfh = $self->open_error_file($tag, "w");
221        $errfh->autoflush(1);
222    
223        while (<P>)
224        {
225            print $errfh $_;
226            print "$tag: $_";
227        }
228    
229        if (!close(P))
230        {
231            my $msg = "error closing $tag pipe: \$?=$? \$!=$!";
232            print $errfh "$msg\n";
233            close($errfh);
234            print "$msg\n";
235            $self->fatal($msg);
236        }
237        close($errfh);
238      $self->log("process $cmd finishes successfully");      $self->log("process $cmd finishes successfully");
239  }  }
240    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3