CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Proc::Background does not take file path with spaces

 



hem
User

Apr 26, 2012, 3:04 PM

Post #1 of 6 (2164 views)
Proc::Background does not take file path with spaces Can't Post

I am trying to use Proc::Background to start a .exe in background. The exe is located in
C:\Program Files (x86)\<sompath>.exe

Proc::Background fails..


Code
my $Command = "C:\\Program Files (x86)\\<somepatth>.exe"; 
my $Id = Proc::Background->new($Command);

Error:
backGround.pl: no executable program located at C:\Program

Is there a way around this problem

Thanks for your time


BillKSmith
Veteran

Apr 26, 2012, 9:00 PM

Post #2 of 6 (2007 views)
Re: [hem] Proc::Background does not take file path with spaces [In reply to] Can't Post

The windows command processor requires double-quotes around filenames which contain spaces.

Untested:


Code
my $Command = '"C:\\Program Files (x86)\\<somepatth>.exe"';



I find that it is usually easier to use the old 8.3 alias for names that contain spaces. I am sure that there is a module to convert path names to that format.
Sorry, I do not have time now to look for it. You can look them up be hand with the /X switch on the windows dir command.
Good Luck,
Bill


hem
User

Apr 26, 2012, 9:23 PM

Post #3 of 6 (1995 views)
Re: [BillKSmith] Proc::Background does not take file path with spaces [In reply to] Can't Post

Thanks Bill

I tried that

Code
my $CommandNew =  '"C:\\Program Files (x86)\\vs.exe"'; 
my $ID = Proc::Background->new($CommandNew)


Error:
Test.pl: cannot find absolute location of "C:\Program

Any ideas?


BillKSmith
Veteran

Apr 27, 2012, 6:13 AM

Post #4 of 6 (1774 views)
Re: [hem] Proc::Background does not take file path with spaces [In reply to] Can't Post

Your problem still has something to do with quotes. Yours look correct, but ... Try this module to bypass the problem.


Code
use Win32; 
.
.
.
my $Command = 'C:\\Program Files (x86)\\vs.exe';
my $commandNew = Win32::GetShortPathName($Command);
my $ID = Proc::Background->new($CommandNew);

Good Luck,
Bill


FishMonger
Veteran / Moderator

Apr 27, 2012, 6:29 AM

Post #5 of 6 (1766 views)
Re: [BillKSmith] Proc::Background does not take file path with spaces [In reply to] Can't Post

An additional recommendation would be to use forward slashes instead of having to escape the backslashes.

There is also the option to use Win32::Process instead of Proc::Background.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Win32::Process;

my $cmd = 'C:/Program Files/TextPad 5/TextPad.exe';

Win32::Process::Create(my $Proc,
$cmd,
'',
0,
DETACHED_PROCESS,
".")|| die ErrorReport();

sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}



hem
User

Apr 27, 2012, 5:10 PM

Post #6 of 6 (1605 views)
Re: [BillKSmith] Proc::Background does not take file path with spaces [In reply to] Can't Post

Thanks Bill . That worked

Appreciate it

In Reply To

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives