Re: Back-slashes & calling a batch file from perl ???
by Michael D Schleif other posts by this author
Oct 28 2005 11:45AM 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:07:21:26-0700] scribed:
> I ran it like this and it seems OK, but I don't have the same conditions:
There's the rub ;>
> 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)";
> }
I have cut-pasted your exact code. Please, recognize that my real code
does use tests of this nature.
Also, please, notice the anomaly I tried to describe in my last post,
regarding whether or not this directory actually gets created (see
below.)
> my $dest = timestamp ();
> if (not -d "$dir/$dest") {
> mkdir "$dir/$dest" or die "mkdir $dir/$dest: $! ($^E)";
> }
>
> do_prog ($prog, $dir, $dest);
>
> exit 0;
>
> # Run system command & return exit code
>
> sub do_prog {
> my ($prog, $dir, $dest) = @_;
>
> $dir =~ s!/!\\!g; # this one you definitely need
> $prog =~ s!/!\\!g; # this may be optional
This is _not_ required, since MS Windows 2003 Server _does_ follow
forward slashes in cmd shell.
> my $cmd = qq{$prog "$dir" $dest};
> print "CMD == ", $cmd, "\n";
>
> # my $null = "NUL";
> # system "$cmd >$null 2>&1";
>
> system $cmd; # seems OK
Again, I get the same results that I have always had at this point.
Your code has not affected my results ;<
> # my @res = `$cmd`; # also tried this OK
> #print "res='@res'\n";
The reason that this is *not* an option is, I need to use the exit codes
from the call to batch file.
> }
>
> # Get date & time string
>
> sub timestamp {
> @_ = localtime ($_[0] ? shift : time);
> return sprintf "%d%02d%02d%02d%02d%02d", $_[5]+1900, $_[4]+1, $_[3], $_[2],
> $_[1], $_[0];
>
> }
>
> __END__
>
> >
> > [A] As is, $prog fails like this:
> >
> > Invalid switch - "backup\20051028070933".
> >
> > Nevertheless, $dir/$dest *DOES* get created.
>
> That's because you do a mkdir in the script ??
<snip />
Please, understand: Whenever I use back-slashes -- however many, however
quoted do far -- this directory does *NOT* get created! Nor does the
Perl code die at the mkdir test ?!?!
Here are my two (2) basic problems:
[A] The called batch file will not accept a file path with
forward-slashes; and
[B] When I pass the directory string _with_ back-slashes, the mkdir :
- does *NOT* create a directory;
- does *NOT* die nor croak any warning;
- function is passed and do_prog() *IS* called;
Of course, since the batch file concatenates $dir and $dest into a
directory path, into which it tries to copy many files, the batch
file *ALWAYS* fails, because there is *NO* directory into which
those files can be copied.
Yes, I know that this is confusing; and I am quite befuddled ;<
Here is information on my development workstation:
System Information:
OS Name MS Windows XP Professional
Version 5.1.2600 SP 1 Build 2600
C:\> perl -v
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 7 registered patches, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Binary build 813 [148120] provided by ActiveState
http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun 6 2005 13:36:37
What do you think?
--
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
|