Re: Back-slashes calling a batch file from perl ???

2005-10-29 Thread Chris Wagner
Forgive me for being so late to jump in.  I'm sure my withdrawn rationality
will prevail.  We need to get back to basic debugging procedures.  Verify
that something does what u think it does.

Mkdir:
D:\perl
mkdir a/b/c/d;
-d /a/b/c/d ? print dirs exist : print dirs don't exist;
^D
dirs don't exist

Your mkdir fails because Perl cannot recursively create directories.
Atleast on build 813.  In ur two dir example it would work if dir1 already
existed. Maybe an interbuild change?  Use shell builtin:
D:\perl
system cmd /c mkdir a\\b\\c\\d;
-d a/b/c/d ? print dirs exist : print dirs don't exist;
^D
dirs exist


At 07:30 AM 10/28/2005 -0500, Michael D Schleif wrote:
[A] As is, $prog fails like this:

  Invalid switch - backup\20051028070933.

Nevertheless, $dir/$dest *DOES* get created.

It says invalid switch because the full arg as passed by perl is
E:/backup\20051028070933.  Everything after the / is interpreted as a switch
by the Windows program - not the batch file.  Simply flip that ONE / into a
\ immediately before the system call.


mkdir $dir/$dest
or die \n\n\tERROR: Cannot create \'$dir/$dest\' : $! : $?\n\n;

Nor, does it get created ;

Don't have an answer for that one.


This code works for me.  Copy and paste this and see what happens.  Dir1
should not preexist.  What args does the bat file see?  Also notice the
system command.  It has weird quotishness that I think has been overlooked.
It does *not* reevaluate \ escapes in whatever was passed to it.  However,
if you feed it a quoted string, the quotes operator *will* evaluate \
escapes before passing that string to system.

===test.pl===
my $prog = D:/testbat.bat;
my $dir = 'D:/dir1';

my $dest = timestamp();
mkdir $dir;
mkdir $dir/$dest;
-d $dir/$dest ? print dirs exist\n : print dirs don't exist\n;
do_prog($prog, $dir, $dest);

sub do_prog {
my ($prog, $dir, $dest) = @_;
$dir =~ s!/!\\!g;
my $cmd = join  , $prog, $dir, $dest;
print CMD is , $cmd, \n;
system $cmd;
}

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

==

===testbat.bat===
@echo off
echo testbat.bat
echo Arg 1 is %1
echo Arg 2 is %2
echo Arg 3 is %3

==


Here is my output:
D:\perl test.pl
dirs exist
CMD is D:/testbat.bat D:\dir1 20051029113850
testbat.bat
Arg 1 is D:\dir1
Arg 2 is 20051029113850
Arg 3 is










--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-29 Thread $Bill Luebkert
Chris Wagner wrote:
 
 Your mkdir fails because Perl cannot recursively create directories.
 Atleast on build 813.  In ur two dir example it would work if dir1 already
 existed. Maybe an interbuild change?  Use shell builtin:
 D:\perl
 system cmd /c mkdir a\\b\\c\\d;
 -d a/b/c/d ? print dirs exist : print dirs don't exist;
 ^D
 dirs exist

If that were the case (that multiple levels of the path need to be created),
he should switch to File::Path::mkpath instead of mkdir.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread Michael D Schleif
* On 2005:10:27:15:07:31-0500 I, Michael D Schleif [EMAIL PROTECTED], scribed:
 I have a perl script that calls a batch file (necessary), and passes it
 two arguments.  The first argument is a directory name, and the second a
 simple label.
 
 When I used forward-slashes (/) everywhere, the perl script behaves as
 expected; but, the batch file refuses to recognize the legitimacy of the
 directory name; at least in the context of passing it to the batch file
 in a system() call, as I need to parse the exit codes.
 
 my $dir = E:/backup;
 
 Yes, I test `-d $dir' successfully.  The batch file refuses to accept
 $dir while using forward-slashes.  I am using s/// to replace (/) with
 any number of (\).  I have tried up to eight (8) back-slashes; but,
 everytime the script mis-behaves, and I have not been able to complete
 this simple task.
 
 What am I missing?
 
 What do you think?

I am sorry that I did not publish any code in the original post.  I have
run into back/forward slash issues on windows before; and I hoped that
there was a simple, code-agnostic solution.

I have reduced the Perl code to this:

#! /usr/bin/perl

require 5;
use diagnostics;
use strict;
use warnings;

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

my $dest = timestamp();
mkdir $dir/$dest;
do_prog($prog, $dir, $dest);

exit 0;

# Run system command  return exit code
sub do_prog {
my ($prog, $dir, $dest) = @_;

# $dir =~ s!/!!g;

my $cmd = join  , $prog, $dir, $dest;
print CMD == , $cmd, \n;

# return 1;

my $null = NUL;
#   system $cmd $null 21;
system $cmd;
1;
}

# 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];
}

==


[A] As is, $prog fails like this:

  Invalid switch - backup\20051028070933.

Nevertheless, $dir/$dest *DOES* get created.

[B] When I do any of these in do_prog:

  $dir =~ s!/!\\!g;
  $dir =~ s!/!!g;
  $dir =~ s!/!\\!g;
  $dir =~ s!/!!g;

I do *NOT* get errors from $prog; but, $dir/$dest does *NOT* get
created.  In the real script, I am doing error checking; and the
following does *NOT* die:

mkdir $dir/$dest
or die \n\n\tERROR: Cannot create \'$dir/$dest\' : $! : $?\n\n;

Nor, does it get created ;

Without that directory, $prog *CANNOT* do what it is intended to do
(e.g., copy files into that directory.)

[C] Obviously, when I use the `return 1;', and bypass system(), then the
directory gets created, regardless of back or forward slashes.

[D] This is supposed to be run as Scheduled Task/cron; so, the $null
issue is to eliminate unnecessary noise.  Whether or not I use that
in this test code does *NOT* seem to affect the results.

[E] $prog itself is copyrighted.  If necessary, I will try and reduce
that, and publish it as well.  It is doing basic batch file stuff,
setting variables and copying files.  Normally, I would convert its
code, and incorporate that into Perl; but, my client is concerned
about future upgrades of the large program, whence $prog comes,
breaking functionality -- the old customizations broken by other
software upgrades problem ;  My Perl program is to be a wrapper to
allow automated, unattended use of this proprietary program.


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 . . .
--


signature.asc
Description: Digital signature
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread $Bill Luebkert
Michael D Schleif wrote:
 * On 2005:10:27:15:07:31-0500 I, Michael D Schleif [EMAIL PROTECTED], 
 scribed:
 I have a perl script that calls a batch file (necessary), and passes it
 two arguments.  The first argument is a directory name, and the second a
 simple label.

 When I used forward-slashes (/) everywhere, the perl script behaves as
 expected; but, the batch file refuses to recognize the legitimacy of the
 directory name; at least in the context of passing it to the batch file
 in a system() call, as I need to parse the exit codes.

 my $dir = E:/backup;

 Yes, I test `-d $dir' successfully.  The batch file refuses to accept
 $dir while using forward-slashes.  I am using s/// to replace (/) with
 any number of (\).  I have tried up to eight (8) back-slashes; but,
 everytime the script mis-behaves, and I have not been able to complete
 this simple task.

 What am I missing?

 What do you think?
 
 I am sorry that I did not publish any code in the original post.  I have
 run into back/forward slash issues on windows before; and I hoped that
 there was a simple, code-agnostic solution.
 
 I have reduced the Perl code to this:
 

I ran it like this and it seems OK, but I don't have the same conditions:

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;

# 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
my $cmd = qq{$prog $dir $dest};
print CMD == , $cmd, \n;

# my $null = NUL;
# system $cmd $null 21;

system $cmd;# seems OK

# my @res = `$cmd`; # also tried this OK
#print res='@res'\n;

}

# 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 ??

 [B] When I do any of these in do_prog:
 
   $dir =~ s!/!\\!g;

This should be fine for any args to the bat file.

   $dir =~ s!/!!g;
   $dir =~ s!/!\\!g;
   $dir =~ s!/!!g;
 
 I do *NOT* get errors from $prog; but, $dir/$dest does *NOT* get
 created.  In the real script, I am doing error checking; and the
 following does *NOT* die:
 
 mkdir $dir/$dest
 or die \n\n\tERROR: Cannot create \'$dir/$dest\' : $! : $?\n\n;
 
 Nor, does it get created ;
 
 Without that directory, $prog *CANNOT* do what it is intended to do
 (e.g., copy files into that directory.)
 
 [C] Obviously, when I use the `return 1;', and bypass system(), then the
 directory gets created, regardless of back or forward slashes.
 
 [D] This is supposed to be run as Scheduled Task/cron; so, the $null
 issue is to eliminate unnecessary noise.  Whether or not I use that
 in this test code does *NOT* seem to affect the results.
 
 [E] $prog itself is copyrighted.  If necessary, I will try and reduce
 that, and publish it as well.  It is doing basic batch file stuff,
 setting variables and copying files.  Normally, I would convert its
 code, and incorporate that into Perl; but, my client is concerned
 about future upgrades of the large program, whence $prog comes,
 breaking functionality -- the old customizations broken by other
 software upgrades problem ;  My Perl program is to be a wrapper to
 allow automated, unattended use of this proprietary program.
 
 
 What do you think?
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread James Sluka




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).

jim

$Bill Luebkert wrote:

  Michael D Schleif wrote:
  
  
* On 2005:10:27:15:07:31-0500 I, Michael D Schleif [EMAIL PROTECTED], scribed:


  I have a perl script that calls a batch file (necessary), and passes it
two arguments.  The first argument is a directory name, and the second a
simple label.

When I used forward-slashes (/) everywhere, the perl script behaves as
expected; but, the batch file refuses to recognize the legitimacy of the
directory name; at least in the context of passing it to the batch file
in a system() call, as I need to parse the exit codes.

my $dir = "E:/backup";

Yes, I test `-d $dir' successfully.  The batch file refuses to accept
$dir while using forward-slashes.  I am using s/// to replace (/) with
any number of (\).  I have tried up to eight (8) back-slashes; but,
everytime the script mis-behaves, and I have not been able to complete
this simple task.

What am I missing?

What do you think?
  

I am sorry that I did not publish any code in the original post.  I have
run into back/forward slash issues on windows before; and I hoped that
there was a simple, code-agnostic solution.

I have reduced the Perl code to this:


  
  
I ran it like this and it seems OK, but I don't have the same conditions:

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;

# 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
my $cmd = qq{$prog "$dir" $dest};
print "CMD == ", $cmd, "\n";

# my $null = "NUL";
# system "$cmd $null 21";

system $cmd;		# seems OK

# my @res = `$cmd`;	# also tried this OK
#print "res='@res'\n";

}

# 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__
  



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread $Bill Luebkert
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 -0E20

 Directory of E:\tmp\backup

10/28/2005  10:51 AMDIR  .
10/28/2005  10:51 AMDIR  ..
   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@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread Michael D Schleif
* $Bill Luebkert [EMAIL PROTECTED] [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 21;
 
 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 NameMS Windows XP Professional
Version5.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 . . .
--


signature.asc
Description: Digital signature
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread James Sluka




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 -0E20

 Directory of E:\tmp\backup

10/28/2005  10:51 AMDIR  .
10/28/2005  10:51 AMDIR  ..
   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@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

  



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread $Bill Luebkert
Michael D Schleif wrote:
 * $Bill Luebkert [EMAIL PROTECTED] [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.

If your mkdir is failing in the Perl script, could there be a permissions
problem ?  You're using /'s instead of \'s like the above right ?

 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.

That's why I said it was optional.  It works either way.
Actually mine works without either of them I believe.

 my $cmd = qq{$prog $dir $dest};
 print CMD == , $cmd, \n;

 # my $null = NUL;
 # system $cmd $null 21;

 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.

You still can get the return code from `` calls:

$CHILD_ERROR
$?  The status returned by the last pipe close, backtick (``) command,
successful call to wait() or waitpid(), or from the system()
operator. This is just the 16-bit status word returned by the wait()
system call (or else is made up to look like it). Thus, the exit
value of the subprocess is really ($?  8), and $?  127 gives
which signal, if any, the process died from, and $?  128 reports
whether there was a core dump. (Mnemonic: similar to sh and ksh.)

 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 ?!?!

Then don't use back slashes.  I created the dir without them - look at
the mkdir's above.

 Here are my two (2) basic problems:
 
 [A] The called batch file will not accept a file path with
 forward-slashes; and

So reverse them just before the system call.

 [B] When I pass the directory string _with_ back-slashes, the mkdir :

I thought the dir was already made before passing the args to the bat file ?

 - does *NOT* create a directory;

The mkdir (in the Perl code) should have already created the dir and it
works fine with slashes, so use them there.

I'm not following you - be more explicit on where the mkdir is - Perl or bat ?

 - 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.

If that's true, you should first concentrate on getting the mkdir in
the Perl script to work so it's there - before you deal with the bat file.

 Yes, I know that this is confusing; and I am quite befuddled ;
 
 Here is information on my development workstation:
 System Information:
 OS NameMS Windows XP Professional
 Version5.1.2600 SP 1 Build 2600

That's what I'm on.

 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)

I'm one behind you there.

 What do you think?

I think you're doin something wrong.  ;)

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread Michael D Schleif
* $Bill Luebkert [EMAIL PROTECTED] [2005:10:28:16:54:19-0700] scribed:
 Michael D Schleif wrote:
  * $Bill Luebkert [EMAIL PROTECTED] [2005:10:28:07:21:26-0700] scribed:
snip /

  I have cut-pasted your exact code.  Please, recognize that my real code
  does use tests of this nature.

Please, take careful note of the above statement.

 If your mkdir is failing in the Perl script, could there be a permissions
 problem ?  You're using /'s instead of \'s like the above right ?

As you know, this is a very complex problem.

[A] When my Perl code _always_ uses forward-slashes, then the Perl mkdir
*DOES* work; but, the BAT cannot use the directory path argument
passed to it.

[B] So, _ALL_ I change is the forward-to-back slashes, and _ONLY_ for
the directory path argument.  Then, the Perl mkdir does *NOTHING*,
and the Perl mkdir does *NOT* croak nor die.  On top of that, the
code continues on into the BAT code, whereupon the BAT cannot do its
job, because its job is to copy files into the dir that was to be
created by the Perl mkdir -- follow the sequence in the sample code.

Yes, this is bizarre behavior.  Yes, this should be a simple case of
swapping slashes.  Unfortunately, this is _not_ that simple ;

  Also, please, notice the anomaly I tried to describe in my last post,
  regarding whether or not this directory actually gets created (see
  below.)
snip /

  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.
 
 You still can get the return code from `` calls:
 
 $CHILD_ERROR
 $?  The status returned by the last pipe close, backtick (``) command,
 successful call to wait() or waitpid(), or from the system()
 operator. This is just the 16-bit status word returned by the 
 wait()
 system call (or else is made up to look like it). Thus, the exit
 value of the subprocess is really ($?  8), and $?  127 
 gives
 which signal, if any, the process died from, and $?  128 
 reports
 whether there was a core dump. (Mnemonic: similar to sh and ksh.)

O, I see -- somehow, I thought that I had gone this route before, and
this was not the case.

I will have to test this, rather than system().  The true test must wait
until Monday, when I have access to the systems on which this must run.

  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 ?!?!
 
 Then don't use back slashes.  I created the dir without them - look at
 the mkdir's above.

Creating the directory with forward-slashes is *NOT* the problem.  Why
is this so hard for me to explain?

The problem is, the BAT will not accept the first argument (%1) as a
directory path when I use forward slashes.  So, I am forced to change
the back-slashes *ONLY* for this argument; and when I do that, then the
previous mkdir does *NOT* happen.

What part of this do you not understand?  How can I make this clearer
for you?

  Here are my two (2) basic problems:
  
  [A] The called batch file will not accept a file path with
  forward-slashes; and
 
 So reverse them just before the system call.

That is _exactly_ what I am doing.  Don't you see that in the sample
code?

  [B] When I pass the directory string _with_ back-slashes, the mkdir :
 
 I thought the dir was already made before passing the args to the bat file ?
 
  - does *NOT* create a directory;
 
 The mkdir (in the Perl code) should have already created the dir and it
 works fine with slashes, so use them there.

Again, this *IS* the crux of the problem!

 I'm not following you - be more explicit on where the mkdir is - Perl or bat ?

Do you see the mkdir in the Perl sample code I have published?

That is the one and only mkdir -- period.

  - does *NOT* die nor croak any warning;
  - function is passed and do_prog() *IS* called;

Did you really read what I wrote there?  Literally, that is what I mean.
No, it does not make sense; but, that *IS* what happens.

  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.
 
 If that's true, you should first concentrate on getting the mkdir in
 the Perl script to work so it's there - before you deal with the bat file.
snip /

I am not allowed to modify the BAT code.  What it does is take two (2)
arguments; and, after some other processing, the BAT code concatenates
the two arguments, like this:

%1\%2

Whereupon, it copies a bunch of files to that path.


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread $Bill Luebkert
Michael D Schleif wrote:
 
 Please, take careful note of the above statement.

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.

 If your mkdir is failing in the Perl script, could there be a permissions
 problem ?  You're using /'s instead of \'s like the above right ?
 
 As you know, this is a very complex problem.
 
 [A] When my Perl code _always_ uses forward-slashes, then the Perl mkdir
 *DOES* work; but, the BAT cannot use the directory path argument
 passed to it.

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

 [B] So, _ALL_ I change is the forward-to-back slashes, and _ONLY_ for
 the directory path argument.  Then, the Perl mkdir does *NOTHING*,

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

 and the Perl mkdir does *NOT* croak nor die.  On top of that, the
 code continues on into the BAT code, whereupon the BAT cannot do its
 job, because its job is to copy files into the dir that was to be
 created by the Perl mkdir -- follow the sequence in the sample code.
 
 Yes, this is bizarre behavior.  Yes, this should be a simple case of
 swapping slashes.  Unfortunately, this is _not_ that simple ;

Yes - it is or you're not splaining yourself very well.

 Creating the directory with forward-slashes is *NOT* the problem.  Why
 is this so hard for me to explain?

Beats me, but you're not.

 The problem is, the BAT will not accept the first argument (%1) as a
 directory path when I use forward slashes.  So, I am forced to change
 the back-slashes *ONLY* for this argument; and when I do that, then the
 previous mkdir does *NOT* happen.

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

 What part of this do you not understand?  How can I make this clearer
 for you?

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

 That is _exactly_ what I am doing.  Don't you see that in the sample
 code?

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.

 Do you see the mkdir in the Perl sample code I have published?
 
 That is the one and only mkdir -- period.

And you said it works if ytou use slashes - so use them.

 Did you really read what I wrote there?  Literally, that is what I mean.
 No, it does not make sense; but, that *IS* what happens.

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

 I am not allowed to modify the BAT code.  What it does is take two (2)
 arguments; and, after some other processing, the BAT code concatenates
 the two arguments, like this:
 
 %1\%2
 
 Whereupon, it copies a bunch of files to that path.

Looks simple enough to me and works for me.

 Yes, it could be.  Please, notice, as I have already stated, I
 cut-pasted the sample code that I was using, and published that intact
 and complete.  I cut-pasted your sample code intact and complete.  My
 empirical results are invariable throughout all trials using both code
 sets.

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 ?

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread Michael D Schleif
* $Bill Luebkert [EMAIL PROTECTED] [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 . . .
--


signature.asc
Description: Digital signature
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-28 Thread $Bill Luebkert
Michael D Schleif wrote:
 
 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.

Stop right there.  That tells me you want to use /'s for the mkdir and
that part is solved.  Now let's go to the calling of the $prog.  If you
than reverse the slashes and call $prog with the \'s (from part #2),
the bat file should be satisfied.  So use the top of #1 and the do_prog
of #2 and you should be fine per your descriptions.

 [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 !?!?

That doesn't make any sense.  The mkdir code is the same.  Did you
rmdir the created dir after running #1 so #2 had the same situation ?

 I know that this is bizarre behavior.  I cannot explain it -- hence, my
 series of incomprehensible posts ;
 
 Is this explication any clearer?

Yes - it's clearer, but can't be true since the code is identical
except for the s///.  Try putting an else on the mkdir ifs and
do a print out if the mkdir is bypassed.  That should help clear
up what's going on there.

EG:

if (not -d $dir) {
mkdir $dir or die mkdir $dir: $! ($^E);
print mkdir $dir completed\n;
} else {
print mkdir $dir not needed\n;
}

And the same for the other ones.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Back-slashes calling a batch file from perl ???

2005-10-27 Thread Michael D Schleif
I have a perl script that calls a batch file (necessary), and passes it
two arguments.  The first argument is a directory name, and the second a
simple label.

When I used forward-slashes (/) everywhere, the perl script behaves as
expected; but, the batch file refuses to recognize the legitimacy of the
directory name; at least in the context of passing it to the batch file
in a system() call, as I need to parse the exit codes.

my $dir = E:/backup;

Yes, I test `-d $dir' successfully.  The batch file refuses to accept
$dir while using forward-slashes.  I am using s/// to replace (/) with
any number of (\).  I have tried up to eight (8) back-slashes; but,
everytime the script mis-behaves, and I have not been able to complete
this simple task.

What am I missing?

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 . . .
--


signature.asc
Description: Digital signature
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-27 Thread $Bill Luebkert
Michael D Schleif wrote:
 I have a perl script that calls a batch file (necessary), and passes it
 two arguments.  The first argument is a directory name, and the second a
 simple label.
 
 When I used forward-slashes (/) everywhere, the perl script behaves as
 expected; but, the batch file refuses to recognize the legitimacy of the
 directory name; at least in the context of passing it to the batch file
 in a system() call, as I need to parse the exit codes.
 
 my $dir = E:/backup;
 
 Yes, I test `-d $dir' successfully.  The batch file refuses to accept
 $dir while using forward-slashes.  I am using s/// to replace (/) with
 any number of (\).  I have tried up to eight (8) back-slashes; but,
 everytime the script mis-behaves, and I have not been able to complete
 this simple task.
 
 What am I missing?
 
 What do you think?

The path you are passing to the batch file will need to use \'s.
Where's your code snippet ?

my $dir = 'c:\foo\bar';
my $label = 'label';
system qq{some-batch.bat $dir $label}; # quoted $dir in case blanks in path
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Back-slashes calling a batch file from perl ???

2005-10-27 Thread Chris Wagner
show some code.




--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs