0

I am trying to write a script that automates other perl scripts. Essentially, I have a few scripts that rollup data for me and need to be run weekly. I also have a couple that need to be run on the weekend to check things and email me if there is a problem. I have the email worked out and everything but the automation. Judging by an internet search, it seems as though using Proc::Background is the way to go. I tried writing a very basic script to test it and can't quite figure it out. I am pretty new to Perl and have never automated anything before (other than through windows task scheduler), so I really don't understand what the code is saying.

My code:

use Proc::Background;

$command = "C:/strawberry/runDir/SendMail.pl";


my $proc1 = Proc::Background -> new($command);

I receive an error that says no executable program located at C:... Can someone explain to me what exactly the code (Proc::Background) is doing? I will then at least have a better idea of how to accomplish my task and debug in the future. Thanks.

David H Hagan
  • 45
  • 2
  • 7
  • Do you have better luck with `\ ` instead of `/`? The shell isn't as flexible as the OS itself. (Don't forget to double the `\ ` in the literal: `"c:\\st..."`. – ikegami Aug 07 '12 at 19:25
  • I ended up getting it to work by throwing 'perl' at the beginning. I'll update the post in a second. – David H Hagan Aug 07 '12 at 20:04

1 Answers1

2

I did notice on Proc::Background's documentation the following:

The Win32::Process module is always used to spawn background processes on the Win32 platform. This module always takes a single string argument containing the executable's name and any option arguments. In addition, it requires that the absolute path to the executable is also passed to it. If only a single argument is passed to new, then it is split on whitespace into an array and the first element of the split array is used at the executable's name. If multiple arguments are passed to new, then the first element is used as the executable's name.

So, it looks like it requires an executable, which a Perl script would not be, but "perl.exe" would be.

I typically specify the "perl.exe" in my Windows tasks as well:

C:\dwimperl\perl\bin\perl.exe "C:\Dropbox\Programming\Perl\mccabe.pl"
Craig Treptow
  • 834
  • 7
  • 19
  • Thanks. I got the command to work by throwing "perl" in front of it so it looks like this: '$command = "perl C:/strawberry/runDir/cmd.pl"' – David H Hagan Aug 08 '12 at 16:01