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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.