ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Re: Back-slashes & calling a batch file from perl ???
by James Sluka other posts by this author
Oct 28 2005 2:07PM messages near this date
view in the new Beta List Site
Re: Back-slashes & calling a batch file from perl ??? | Re: Back-slashes & calling a batch file from perl ???
I agree bill, it does not make sense, nonetheless on my win98 machine 
(creak creak), the extra space is required.

jim

$Bill Luebkert wrote:

> James Sluka wrote:
>   
> 
> >One more thing to try is to add a trailing space after the directory
> >spec, as in;
> >    system qq{$prog "$dir " $dest}
> >or
> >    my $cmd = qq{$prog "$dir "  "$dest"};
> >
> >I did some quick tests with;
> >##########Perl code
> >my $prog = 'c:\windows\desktop\some-batch.bat';
> >my $dir  = 'c:\windows\desktop\jim';    # no trailing backslash
> >my $dest = 'thelabel';
> >
> ># both the directory and batch files do exist
> >if (-e $prog) {print "prog found\n"} else {print "prog NOT found\n"};
> >if (-d $dir)  {print "dir  found\n"} else {print "dir  NOT found\n"};
> >
> ># Version 1, works
> >system qq{$prog "$dir " $dest}; # quoted $dir in case blanks in path
> >                                # and note the extra space in "$dir "
> >
> ># Version 2, works
> >my $cmd = qq{$prog "$dir "  "$dest"}; # note the extra space in "$dir "
> >print "\n\nCMD ==", $cmd, "=\n";
> >system "$cmd";
> ># end Perl code
> >
> >### some-batch.bat contains
> >echo %1
> >echo %2
> >dir %1
> >
> >The perl code above fails if the trailing space after the dir spec is
> >omitted. The space can be in the original variable or added when the
> >command is created (as I did above).
> >    
> >
> 
> That doesn't make any sense.  There's already one space there why would
> putting two there make a difference ?  Mine worked with just one.
> A trailing \ may make some change, but an extra space seems pretty
> redundant.
> 
> This works fine for me:
> 
> if (-e $prog) { print "$prog found\n" } else { print "$prog NOT found\n" };
> if (-d $dir)  { print "$dir  found\n" } else {
>   mkdir $dir or die; print "$dir NOT found created\n" };
> 
> # $dir =~ s/\//\\/g;	# this is optional for me
> 
> system qq{$prog "$dir" $dest};
> 
> The bat file produces (for my version) :
> 
> %0 = E:/tmp/nvhotbackup.bat
> %1 = "E:/tmp/backup"
> %2 = thelabel
> 
> dir "E:/tmp/backup"
>  Volume in drive E is DATA120
>  Volume Serial Number is 0000-0E20
> 
>  Directory of E:\tmp\backup
> 
> 10/28/2005  10:51 AM    <DIR>          .
> 10/28/2005  10:51 AM    <DIR>          ..
>                0 File(s)              0 bytes
>                2 Dir(s)   7,019,872,256 bytes free
> 
> errorlevel = 0
> cmdline = cmd /c "E:/tmp/nvhotbackup.bat "E:/tmp/backup" thelabel"
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@[...].com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
>   
> 
Attachments:
unknown1
unknown2
unknown3
unknown4

Thread:
Michael D Schleif
Michael D Schleif
Chris Wagner
$Bill Luebkert
$Bill Luebkert
Michael D Schleif
$Bill Luebkert
Michael D Schleif
$Bill Luebkert
Michael D Schleif
$Bill Luebkert
James Sluka
Ted Zeng
$Bill Luebkert
Ted Zeng
Paul
Peter Eisengrein
Trevor Joerges
Jim Guion
$Bill Luebkert
James Sluka
$Bill Luebkert
Chris Wagner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved