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: spidering/crawling/scraping a site..

2005-10-28 Thread Thomas, Mark - BLS CTR
Bruce,

Hehe... Gotta hand it to ya, you posted code this time :)

Here's what's going on. WWW::CheckSite::Spider is using the Mech class you
specify. You specified a class by the name of BA_Mech. So what you have to
do in your BA_Mech class is provide the information you need to log in. Make
BA_Mech a subclass of WWW::Mechanize and override the method(s) you would
need to change. In the case of the standard HTTP server-based Basic
Authentication, you would only need to provide a get_basic_credentials
method with your username and password. But in your case, you'd probably
need to override new() to call SUPER::new then perform the form-based login
before returning the Mech object's handle.

If you're not familiar with OO and subclassing, you will probably find it
easier to use my second suggestion, which was to perform
$mech-extract_links on each page and put the links in an array or hash to
keep track of which ones you still need to follow. Then you follow them
until you're done.

If the result of all this is to mirror pages and /then/ scrape, you're
making it too complicated. Skip the mirroring, and scrape as you fetch.

- Mark.



 -Original Message-
 From: bruce [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, October 27, 2005 5:04 PM
 To: Thomas, Mark - BLS CTR; 'perl-win32-users mailing list'
 Subject: RE: spidering/crawling/scraping a site..
 
 hi...
 
 decided to try to use the www::checksite::spider to try to 
 create/write a
 quick spider for the http://jobboardsoftware.biz/demo/admin/login.apsx
 site...
 
 i blew it!!!
 
 the following code gives me some sort of hash, but i'm pretty 
 sure i haven't
 correctly filled in the login (user/passwd) form correctly...
 
 any thoughts??
 
 i'm not exactly sure what the BA_Mech is doing, or why it 
 might be needed. i
 tried to do the form submit directly from the spider, but the 
 perl code
 threw an error..
 
 so, basically, i'm guessing!!!
 
 
 package BA_Mech;
 use base 'WWW::Mechanize';
 
 $mech = WWW::Mechanize-new();
 my $start1 = http://jobboardsoftware.biz/demo/admin/login.aspx;;
 $mech-get($start1);
 $mech-submit_form(
form_name = 'Form1',
button= 'Button1',
fields = {
username = 'demo',
password = 'demo'
  }
);
 
 
 package Main;
 use WWW::CheckSite::Spider;
 
 my $start = http://jobboardsoftware.biz/demo/admin/login.aspx;;
 
 my $sp = WWW::CheckSite::Spider-new(
 ua_class = 'BA_Mech',
 uri = $start,
 );
 
 while (my $page = $sp-get_page)
 {
 print $page;
 print \n;
 }
 die;
 
 -bruce
 
 
 
 
 -Original Message-
 From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
 Sent: Thursday, October 27, 2005 10:34 AM
 To: '[EMAIL PROTECTED]'
 Subject: RE: spidering/crawling/scraping a site..
 
 
 OK, there's a difference between using standard HTTP 
 authentication (the
 browser dialog box) and form-based authentication (which every site
 implements differently). If it is the former, most mirroring 
 tools can do it
 already. But if authentication is done through the web app like your
 example, you'll have to use Mech.
 
 - Mark.
 
  -Original Message-
  From: bruce [mailto:[EMAIL PROTECTED]
  Sent: Thursday, October 27, 2005 1:22 PM
  To: Thomas, Mark - BLS CTR
  Subject: RE: spidering/crawling/scraping a site..
 
  thanks!!!
 
  i would have thought that there would have been a bunch of
  little/big apps
  that were used to parse user/passwd protected login fom sites...
 
  guess i was wrong..
 
 
  but this isn't for some evil/take over the world project.
  i've got a few
  sites that i'm looking at, that are passwd/login protected.
  rather than
  loign to the sites, i thought i'd scrape them, and then compare them
  locally, when i wanted. which is why i was saying i didn't
  think this was
  going to be more than a few minutes
 
  -bruce
 
 
  -Original Message-
  From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
  Sent: Thursday, October 27, 2005 9:51 AM
  To: '[EMAIL PROTECTED]'
  Subject: RE: spidering/crawling/scraping a site..
 
 
  Oh, you want a MIRRORING app that will mirror stuff that you
  have to log in
  to get! Correct terminology is everything. What nefarious
  purposes do you
  want that for?
 
  What you need is something that can use a Mech object to
  spider with. You
  get the Mech object logged in, then pass it to the spider,
  which does its
  dirty deed.
 
  You're probably the only person in the world that wants to do
  that. So you
  probably won't find anything that does it out-of-the-box, but
  I found a
  module that uses a Mech object to mirror a site:
  WWW::CheckSite::Spider. It
  only takes a start URI, but it's probably a small
  modification to make it
  accept a Mech object that is already logged in. Then you'd be
  able to scrape
  all the pages.
 
  Of course writing a Mech spider yourself is an option, and I
  say it would be
  simple, as there is already an extract_links() 

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: spidering/crawling/scraping a site..

2005-10-28 Thread bruce
mark...

i'm actually faced with a greater issue. i'm looking to
crawl/extract/download the site. simply scraping each site doesn't get me
the underlying files for the site, in the correct location/names on my
server, to allow me to kind of replicate the basic links of the site.

this requires a crawler... which is what i was originally looking for/hoping
for, that allows me to deal with the login (user/passwd) form.

-bruce


-Original Message-
From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
Sent: Friday, October 28, 2005 7:06 AM
To: '[EMAIL PROTECTED]'; 'perl-win32-users mailing list'
Subject: RE: spidering/crawling/scraping a site..


Bruce,

Hehe... Gotta hand it to ya, you posted code this time :)

Here's what's going on. WWW::CheckSite::Spider is using the Mech class you
specify. You specified a class by the name of BA_Mech. So what you have to
do in your BA_Mech class is provide the information you need to log in. Make
BA_Mech a subclass of WWW::Mechanize and override the method(s) you would
need to change. In the case of the standard HTTP server-based Basic
Authentication, you would only need to provide a get_basic_credentials
method with your username and password. But in your case, you'd probably
need to override new() to call SUPER::new then perform the form-based login
before returning the Mech object's handle.

If you're not familiar with OO and subclassing, you will probably find it
easier to use my second suggestion, which was to perform
$mech-extract_links on each page and put the links in an array or hash to
keep track of which ones you still need to follow. Then you follow them
until you're done.

If the result of all this is to mirror pages and /then/ scrape, you're
making it too complicated. Skip the mirroring, and scrape as you fetch.

- Mark.



 -Original Message-
 From: bruce [mailto:[EMAIL PROTECTED]
 Sent: Thursday, October 27, 2005 5:04 PM
 To: Thomas, Mark - BLS CTR; 'perl-win32-users mailing list'
 Subject: RE: spidering/crawling/scraping a site..

 hi...

 decided to try to use the www::checksite::spider to try to
 create/write a
 quick spider for the http://jobboardsoftware.biz/demo/admin/login.apsx
 site...

 i blew it!!!

 the following code gives me some sort of hash, but i'm pretty
 sure i haven't
 correctly filled in the login (user/passwd) form correctly...

 any thoughts??

 i'm not exactly sure what the BA_Mech is doing, or why it
 might be needed. i
 tried to do the form submit directly from the spider, but the
 perl code
 threw an error..

 so, basically, i'm guessing!!!


 package BA_Mech;
 use base 'WWW::Mechanize';

 $mech = WWW::Mechanize-new();
 my $start1 = http://jobboardsoftware.biz/demo/admin/login.aspx;;
 $mech-get($start1);
 $mech-submit_form(
form_name = 'Form1',
button= 'Button1',
fields = {
username = 'demo',
password = 'demo'
  }
);


 package Main;
 use WWW::CheckSite::Spider;

 my $start = http://jobboardsoftware.biz/demo/admin/login.aspx;;

 my $sp = WWW::CheckSite::Spider-new(
 ua_class = 'BA_Mech',
 uri = $start,
 );

 while (my $page = $sp-get_page)
 {
 print $page;
 print \n;
 }
 die;

 -bruce




 -Original Message-
 From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
 Sent: Thursday, October 27, 2005 10:34 AM
 To: '[EMAIL PROTECTED]'
 Subject: RE: spidering/crawling/scraping a site..


 OK, there's a difference between using standard HTTP
 authentication (the
 browser dialog box) and form-based authentication (which every site
 implements differently). If it is the former, most mirroring
 tools can do it
 already. But if authentication is done through the web app like your
 example, you'll have to use Mech.

 - Mark.

  -Original Message-
  From: bruce [mailto:[EMAIL PROTECTED]
  Sent: Thursday, October 27, 2005 1:22 PM
  To: Thomas, Mark - BLS CTR
  Subject: RE: spidering/crawling/scraping a site..
 
  thanks!!!
 
  i would have thought that there would have been a bunch of
  little/big apps
  that were used to parse user/passwd protected login fom sites...
 
  guess i was wrong..
 
 
  but this isn't for some evil/take over the world project.
  i've got a few
  sites that i'm looking at, that are passwd/login protected.
  rather than
  loign to the sites, i thought i'd scrape them, and then compare them
  locally, when i wanted. which is why i was saying i didn't
  think this was
  going to be more than a few minutes
 
  -bruce
 
 
  -Original Message-
  From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
  Sent: Thursday, October 27, 2005 9:51 AM
  To: '[EMAIL PROTECTED]'
  Subject: RE: spidering/crawling/scraping a site..
 
 
  Oh, you want a MIRRORING app that will mirror stuff that you
  have to log in
  to get! Correct terminology is everything. What nefarious
  purposes do you
  want that for?
 
  What you need is something that can use a Mech object to
  spider with. You
  get 

RE: spidering/crawling/scraping a site..

2005-10-28 Thread Thomas, Mark - BLS CTR
bruce [mailto:[EMAIL PROTECTED] wrote:
 mark...
 
 i'm actually faced with a greater issue. i'm looking to
 crawl/extract/download the site. simply scraping each site 
 doesn't get me
 the underlying files for the site, in the correct location/names on my
 server, to allow me to kind of replicate the basic links of the site.

Aside from the questionable legality of what you're asking, keep in mind
that sites using database-backed form-based authentication (as opposed to
HTTP Basic Authentication) are often generated via assembly from includes or
CMSes or other applications, in which case trying to get the underlying
files is futile. They may not exist as discrete files on the server.

 this requires a crawler... which is what i was originally 
 looking for/hoping
 for, that allows me to deal with the login (user/passwd) form.

I have given you the information you need to do this. Simply save the files
locally as you crawl them.

- Mark.

___
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


eval'ing a dumped data structure

2005-10-28 Thread Joe Discenza
Title: RE: spidering/crawling/scraping a site..






All,

I've gota dumped data 
structure. I can print the string I dumped to:

$form_hash_ary_ref = 
[ 
{ 
'desc' = 'Agreement to Provide 
Insurance', 
'name' = 
'AGREE_PPI.pdf', 
'copies' = 
1, 
'field_hash' = 
{ 
'INS_POLICY_NUM' = 
{ 
'disp_only' = 
1, 
'value' = 
'cpsex1' 
}}
 
}
];

This is fine, and looks just like I 
expect. Then I eval the dumped string, so the variable $form_hash_ary_ref should 
contain that anonymous array (in the example, containing one anonymous 
hash).

I have a debug line right after the 
eval

 print DEBUG 
ref($form_hash_ary_ref), ": @{$form_hash_ary_ref}\n";
and it prints
ARRAY: HASH(0xd5bea64)
I expected the ARRAY (ref of a reference to an array), and then I 
suppose it prints the single element of the array, which is a hash ref.

Then I get to the next debug line

@form_hash_ary = @$form_hash_ary_ref; 
print DEBUG scalar(@form_hash_ary), 
$form_hash_ary[0]{'field_hash'}{'INS_POLICY_NUM'}{'value'}, "\n" if ($debug 
 $next_form == -1);
This prints what I expect

1cpsex1

(Yeah, I should probably have put a space between them.)

But this next line crashes, and I can't figure out why (it's in 
ASP, and I'm not getting a Perl run-time error back, just a 500).

my %my_hash = 
%{$form_hash_ary[$current_form]{'field_hash'}};

When I lift the chunk out into a console .pl file, hard-code the 
string to be eval'ed, everything works fine.

Any clues?

Joe


== 
Joseph P. Discenza, Sr. 
Programmer/Analyst 
mailto:[EMAIL PROTECTED] 
Carleton Inc. http://www.carletoninc.com 
574.243.6040 ext. 300 fax: 574.243.6060Providing 
Financial Solutions and Compliance for over 30 Years



___
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: eval'ing a dumped data structure

2005-10-28 Thread Joe Discenza
Title: RE: spidering/crawling/scraping a site..







All,

Please disregard. It was another 
value not updating, and I've got it fixed. Thanks for your 
attention.

Joe


== 
Joseph P. Discenza, Sr. 
Programmer/Analyst 
mailto:[EMAIL PROTECTED] 
Carleton Inc. http://www.carletoninc.com 
574.243.6040 ext. 300 fax: 574.243.6060Providing 
Financial Solutions and Compliance for over 30 Years


From: 
[EMAIL PROTECTED] on behalf of Joe 
DiscenzaSent: Fri 28-Oct-05 14:17To: perl-win32-users 
mailing listSubject: eval'ing a dumped data 
structure


All,

I've gota dumped data 
structure. I can print the string I dumped to:

$form_hash_ary_ref = 
[ 
{ 
'desc' = 'Agreement to Provide 
Insurance', 
'name' = 
'AGREE_PPI.pdf', 
'copies' = 
1, 
'field_hash' = 
{ 
'INS_POLICY_NUM' = 
{ 
'disp_only' = 
1, 
'value' = 
'cpsex1' 
}}
 
}
];

This is fine, and looks just like I 
expect. Then I eval the dumped string, so the variable $form_hash_ary_ref should 
contain that anonymous array (in the example, containing one anonymous 
hash).

I have a debug line right after the 
eval

 print DEBUG 
ref($form_hash_ary_ref), ": @{$form_hash_ary_ref}\n";
and it prints
ARRAY: HASH(0xd5bea64)
I expected the ARRAY (ref of a reference to an array), and then I 
suppose it prints the single element of the array, which is a hash ref.

Then I get to the next debug line

@form_hash_ary = @$form_hash_ary_ref; 
print DEBUG scalar(@form_hash_ary), 
$form_hash_ary[0]{'field_hash'}{'INS_POLICY_NUM'}{'value'}, "\n" if ($debug 
 $next_form == -1);
This prints what I expect

1cpsex1

(Yeah, I should probably have put a space between them.)

But this next line crashes, and I can't figure out why (it's in 
ASP, and I'm not getting a Perl run-time error back, just a 500).

my %my_hash = 
%{$form_hash_ary[$current_form]{'field_hash'}};

When I lift the chunk out into a console .pl file, hard-code the 
string to be eval'ed, everything works fine.

Any clues?

Joe


== 
Joseph P. Discenza, Sr. 
Programmer/Analyst 
mailto:[EMAIL PROTECTED] 
Carleton Inc. http://www.carletoninc.com 
574.243.6040 ext. 300 fax: 574.243.6060Providing 
Financial Solutions and Compliance for over 30 Years



___
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