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

I haven't been using Perl for very long so I'm hoping that someone can steer me in the right direction with this.

I need to run an external batch script from a Perl script to automate some testing I'm performing. This batch script monitors a directory for changes (files added, deleted, modified) and updates a web server accordingly (installing an application added to the folder, for example). When I call the batch script using system(), it starts monitoring the directory, but it doesn't allow me to proceed onto the next statement in my script (which is to copy a file into the directory) until the monitoring ends.

I suppose I need a separate process or thread to run which waits until the batch script is run and finished setting up the monitoring before copying a file into the monitored directory. I'm not sure what the best way to approach this is and I need a technique that works on both Linux and Windows.

Any suggestions?

  • Comment on Copying a file while running an external batch script

Replies are listed 'Best First'.
Re: Copying a file while running an external batch script
by moritz (Cardinal) on Jul 07, 2008 at 14:18 UTC
    You can either start your program in the background (on unix: system('yourprogram &');) or fork and exec in the child.

    See also IPC::Run and perlipc.

Re: Copying a file while running an external batch script
by massa (Hermit) on Jul 07, 2008 at 14:24 UTC
    use Proc::Background; my $proc = new Proc::Background 'your_script_name'; $proc->alive; ## returns true while the process is still alive $proc->die; $proc->wait;
    []s, HTH, Massa
Re: Copying a file while running an external batch script
by Anonymous Monk on Jul 07, 2008 at 14:21 UTC
    help cmd help start cmd /c start foobar.bat