Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Proc::Background does not take file path with spaces by Anonymous Monk
in thread Proc::Background does not take file path with spaces by dinasour

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found