in reply to Proc::Background does not take file path with spaces

Hey Guys,

**** VICTORY ****

I know this is old but I was trying to do the exact same thing on Windows XP running
Strawberry Perl 5.8.18, and also using the Proc::Background Module. And I was literally
on the verge of ripping my hair out one strand at a time..! Seriously!

But I was FINALLY able to get Proc::Background to work using Absolute Paths that contain
whitespace..!

What I had to do was, first define the full path, then convert the Full Path to Windows Short
Path to remove the whitespace. Lastly, include "perl" before the script name you want to execute
in Proc::Background->new() Function... Like so:
### Full Path to Background Script: my $FULL_PATH = "C:\\Program Files\\Script_Dir\\my_script.pl"; ### Converts the FULL_PATH to a Win32 "Short Pathname" my $short_path = Win32::GetShortPathName($FULL_PATH); ### Prepend "perl " to before your script's path: # *my Array '@args' is just a space separated list of arguments my $proc = Proc::Background->new("perl $short_path @args"); ### Check if the Job is still alive... 1==YES, 0==NO my $alive = $proc->alive; ### While $alive is NOT '0', then it's still running... while ($alive ne 0) { $alive = $proc->alive; if ($alive ne 0) { print "PROCESS IS STILL RUNNING...\n"; } else { print "PROCESS IS NO LONGER RUNNING...\n"; } sleep 1; }
Without pre-pending "perl" to the $short_path variable you would get the following error
even though it could actually find the Path this time instead of saying its not there for "C:\Program"
and stopping at the first occurrence of whitespace. So you would see this without including "perl":
> no executable program located at C:\PROGRA~1\SCRIPT~1\MY_SC~2.PL

And after I added "perl" to the Proc::Background command I can now execute my script in the background
and watch it's progress...

So I hope this helps someone out there, cause this was the first link that would show up in Google
no matter what search terms I used for describing this problem...


So good luck gents...!


Thanks,
Matt