create a batch file

K

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
=================
 
P

Peter Makholm

king said:
#!\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
 
K

Klaus

#!\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* ?
 
P

Peter Wyzl

Klaus said:
#!\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
 
A

A. Sinan Unur

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top