create a batch file

create a batch file

am 23.10.2007 14:56:21 von king

#!\c\perl\bin
use strict;
my $register="f0088";
open(fh,">check.bat")
print fh "\@echo\n";
print fh "\@echo Comparing X16 reg\n";
print fh "check $register > test.log\n";
print fh "fc /l log test.log > comp.log\n";
print fh "find \"no differences encountered\" comp.log\n";
print fh "if errorlevel 1 goto fail1\n";
print fh "echo fine\n";
print fh "del test.log\n";

close (fh);

while running this file to create a batch file I am getting a error
saying error at print.

I want to create a batch file named check.bat which should contain the
below things: and the $ register value need to be replaced.
===============
@echo
@echo Comparing X16 reg
check $register > test.log
fc /l log test.log > comp.log
find \"no differences encountered\" comp.log
if errorlevel 1 goto fail1
echo fine
del test.log
=================

Re: create a batch file

am 23.10.2007 15:02:44 von Peter Makholm

king writes:

> #!\c\perl\bin
> use strict;
> my $register="f0088";
> open(fh,">check.bat")
> print fh "\@echo\n";
> print fh "\@echo Comparing X16 reg\n";
> print fh "check $register > test.log\n";
> print fh "fc /l log test.log > comp.log\n";
> print fh "find \"no differences encountered\" comp.log\n";
> print fh "if errorlevel 1 goto fail1\n";
> print fh "echo fine\n";
> print fh "del test.log\n";
>
> close (fh);

This have a syntax error. It can't be what you have been running to
produce the followin.

> ===============
> @echo
> @echo Comparing X16 reg
> check $register > test.log
> fc /l log test.log > comp.log
> find \"no differences encountered\" comp.log
> if errorlevel 1 goto fail1
> echo fine
> del test.log
> =================

This is not what is being produced by a script not quite unlike the
above script. I get neither escaped double quotes nor uninterpolated
$register.

//Makholm

Re: create a batch file

am 23.10.2007 15:15:16 von Klaus

On Oct 23, 2:56 pm, king wrote:
> #!\c\perl\bin

assuming you are running on windows, that would be better written as
(although I don't think it matters on windows)

#!c:\perl\bin\perl

> use strict;

it is recommended to add
use warnings;

> my $register="f0088";
> open(fh,">check.bat")

There is a semicolon missing at the end of the line, but more
importantly, it is recommended to
1. *always* check the return code after open
2. use lexical filehandles
3. use the 3-parameter form of open

open my $fh, '>', 'check.bat' or die "Error open check.bat: $!";

> print fh "\@echo\n";
print {$fh} "\@echo\n";

[ snip and re-arranged ]

> I want to create...
> find \"no differences encountered\" comp.log

> print fh "find \"no differences encountered\" comp.log\n";
print {$fh} qq{find \\"no differences encountered\\" comp.log\n};

> close (fh);
close $fh;

> while running this file to create a batch file I am getting a error
> saying error at print.

Is this error message *exact* and *complete* ?

--
Klaus

Re: create a batch file

am 23.10.2007 15:53:35 von Peter Wyzl

"Klaus" wrote in message
news:1193145316.202070.279290@e34g2000pro.googlegroups.com.. .
> On Oct 23, 2:56 pm, king wrote:
>> #!\c\perl\bin
>
> assuming you are running on windows, that would be better written as
> (although I don't think it matters on windows)
>
> #!c:\perl\bin\perl
>
>> use strict;
>
> it is recommended to add
> use warnings;
>
>> my $register="f0088";
>> open(fh,">check.bat")
>
> There is a semicolon missing at the end of the line, but more
> importantly, it is recommended to
> 1. *always* check the return code after open
> 2. use lexical filehandles
> 3. use the 3-parameter form of open
>
> open my $fh, '>', 'check.bat' or die "Error open check.bat: $!";
>
>> print fh "\@echo\n";
> print {$fh} "\@echo\n";
>
> [ snip and re-arranged ]
>
>> I want to create...
>> find \"no differences encountered\" comp.log
>
>> print fh "find \"no differences encountered\" comp.log\n";
> print {$fh} qq{find \\"no differences encountered\\" comp.log\n};

print $fh 'find "no differences encountered" comp.log', "\n";

P

Re: create a batch file

am 23.10.2007 20:21:37 von 1usa

Klaus wrote in news:1193145316.202070.279290
@e34g2000pro.googlegroups.com:

> On Oct 23, 2:56 pm, king wrote:
>> #!\c\perl\bin
>
> assuming you are running on windows, that would be better written as
> (although I don't think it matters on windows)
>
> #!c:\perl\bin\perl

Well, that certainly better than the non-sensical path (to Windows) the
OP was using.

The only case where it might matter what path to perl you put in the
shebang line on Windows is when you are using Apache to run CGI scripts
and you have not heard of
http://httpd.apache.org/docs/2.2/mod/core.html#scriptinterpr etersource

I have found it convenient to leave the shebang lines of my scripts as

#!/usr/bin/perl

which is usually a symlink to the system default perl on the *nix
systems I have access to.

Sinan


--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: