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 Michael D Schleif other posts by this author
Oct 28 2005 9:05PM 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 ???
* $Bill Luebkert <dbecoll@[...].net>  [2005:10:28:19:49:55-0700] scribed:
<snip /> 

>  The fact that you used the same code means nothing since 1) we seem to be
>  talking apples and oranges and 2) your bat file is different.
<snip /> 

>  Then you don't have a problem - use the forward slashes to do the mkdir.
<snip /> 

>  NO!!!! You just said it worked with forward slashes - so use forward slashes.
>  Switch the slashes *AFTER* you do the mkdir.
<snip /> 

>  Yes - it is or you're not splaining yourself very well.
<snip /> 

>  Beats me, but you're not.
<snip /> 

>  You're not getting it.  Use forward slashes *ONLY* for the Perl script
>  mkdir and then switch to back slashes.
<snip /> 

>  You're doing a terrible job and I'm trying to be clearer than you are.
<snip /> 

>  Yes, but you said it fails.  It should work cause you said it works
>  with back slashes.  You're doing a terrible job of explaining your
>  slashes.
<snip /> 

>  And you said it works if ytou use slashes - so use them.
<snip /> 

>  No - you haven't explained anything where I can understand it.  You keep
>  contradicting yourself (at least that's what I'm reading).
<snip /> 

>  Looks simple enough to me and works for me.
<snip /> 

>  What you're not getting across is where the problem is.
>  
>  You said the mkdir works with forward slashes and the bat file works
>  with back slashes.  So use forward on the mkdir and back on the bat call.
>  It's that simple.  Now where does it fail under those circumstances ?


One more way to explain this:

[A] Using Code #1, the Perl mkdir successfully creates $dir/$dest, and
goes on to call $prog.  $prog fails, because it will not accept $dir as
a valid directory while using forward-slashes (/).  At one trial, the
stderr returned was this:

    Invalid switch - "backup\20051028070933".

[B] Using Code #2, the Perl mkdir does *NOT* create $dir/$dest; nor does
it croak, nor does it die !?!?  Nevertheless, the Perl code goes into
$prog; but, the BAT code cannot copy files into %1\%2, because that
directory does *NOT* exist, because the Perl code somehow did *NOT*
mkdir it !?!?


I know that this is bizarre behavior.  I cannot explain it -- hence, my
series of incomprehensible posts ;<

Is this explication any clearer?


###  Code #1 : BEGIN  ####

#! /usr/bin/perl
use diagnostics;
use strict;
use warnings;

my $prog = "E:/usr/ov/bin/nvhotbackup.bat";
my $dir = 'E:/backup';

if (not -d $dir) {
    mkdir $dir or die "mkdir $dir: $! ($^E)";
}
my $dest = timestamp ();
if (not -d "$dir/$dest") {
    mkdir "$dir/$dest" or die "mkdir $dir/$dest: $! ($^E)";
}
do_prog ($prog, $dir, $dest);

exit 0;

sub do_prog {
    my ($prog, $dir, $dest) = @_;
    ###  Substitution line omitted  ###
    my $cmd = qq{$prog "$dir" $dest};
    print "CMD == ", $cmd, "\n";
    system $cmd;            # seems OK
}

sub timestamp {
    @_ = localtime ($_[0] ? shift : time);
    return sprintf "%d%02d%02d%02d%02d%02d",
        $_[5]+1900, $_[4]+1,
        $_[3], $_[2], $_[1], $_[0];
}
__END__

###  Code #1 : END  ####


###  Code #2 : BEGIN  ####

#! /usr/bin/perl
use diagnostics;
use strict;
use warnings;

my $prog = "E:/usr/ov/bin/nvhotbackup.bat";
my $dir = 'E:/backup';

if (not -d $dir) {
    mkdir $dir or die "mkdir $dir: $! ($^E)";
}
my $dest = timestamp ();
if (not -d "$dir/$dest") {
    mkdir "$dir/$dest" or die "mkdir $dir/$dest: $! ($^E)";
}
do_prog ($prog, $dir, $dest);

exit 0;

sub do_prog {
    my ($prog, $dir, $dest) = @_;
    $dir =~ s!/!\\!g;       # this one you definitely need
    my $cmd = qq{$prog "$dir" $dest};
    print "CMD == ", $cmd, "\n";
    system $cmd;            # seems OK
}

sub timestamp {
    @_ = localtime ($_[0] ? shift : time);
    return sprintf "%d%02d%02d%02d%02d%02d",
        $_[5]+1900, $_[4]+1,
        $_[3], $_[2], $_[1], $_[0];
}
__END__

###  Code #2 : END  ####


-- 
Best Regards,

mds
mds resource
877.596.8237
-
Dare to fix things before they break . . .
-
Our capacity for understanding is inversely proportional to how much
we think we know.  The more I know, the more I know I don't know . . .
--
Attachments:
signature.asc
unknown1
unknown2
unknown3

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