SPUG: exec question

Dan Ebert mathin at mathin.com
Fri Feb 11 09:46:17 PST 2005


Here are some more details ... this is what I have:

$script = '/home/dan/script.pl';
$config = '/home/dan/config.cfg';
$file_to_process = '/path/to/file';

exec($script,$config,$file_to_process);

(The $script expects 2 commandline args, the config file and the file to
process.)

I don't need to capture STDOUT or STDERR (the script executed has logging
built in to it).

The solution you suggest will probably work, I'm just curious why exec
isn't returning immediately and the script exiting.  I thought that was
what exec was supposed to do?

Dan.
----------------------------------------------------------
Immigration is the sincerest form of flattery.
	- Unknown
----------------------------------------------------------


On Fri, 11 Feb 2005, Tim Maher wrote:

> On Fri, Feb 11, 2005 at 09:23:16AM -0800, Dan Ebert wrote:
> > I have a script which manages a bunch of other scripts.  Basically it
> > kicks off a specific script depending on the situation it sees when it
> > runs.
> >
> > I want it to kick off the script then exit without waiting around for the
> > other script to finish.  I thought this would do it:
> >
> > # code to decide what script to use
> > exec($script);
> > but the manager script doesn't exit when it does the exec.  Any ideas?
> > Thanks,
> >
> > Dan.
>
> If $script contains the name of a file with a proper shebang line,
> and you're on UNIX or Linux, and $PATH is set to the directory $script
> is in or $script contains the pathname directory itself, then
> something like this might be what you're after:
>
> system "nohup $script > /tmp/output.$$ 2>&1 &" ;
>
> That command runs $script in the background (so the parent won't
> wait for it to complete), with STDOUT and STDERR redirected to
> a unique filename.
>
> -Tim
> *--------------------------------------------------------------------------*
> | Tim Maher, PhD     (206) 781-UNIX      (866) DOC-PERL     (866) DOC-UNIX |
> | tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  http://TeachMeUnix.Com |
> *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
> |      Watch for my upcoming book: "Minimal Perl for UNIX/Linux People"    |
> *--------------------------------------------------------------------------*
>



More information about the spug-list mailing list