create a batch file

Discussion in 'Perl Misc' started by king, Oct 23, 2007.

  1. king

    king Guest

    #!\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
    =================
    king, Oct 23, 2007
    #1
    1. Advertising

  2. 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
    Peter Makholm, Oct 23, 2007
    #2
    1. Advertising

  3. king

    Klaus Guest

    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
    Klaus, Oct 23, 2007
    #3
  4. king

    Peter Wyzl Guest

    "Klaus" <> wrote in message
    news:...
    > 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
    Peter Wyzl, Oct 23, 2007
    #4
  5. 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#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


    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)
    clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
    A. Sinan Unur, Oct 23, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raterus
    Replies:
    1
    Views:
    939
    Patrice
    Apr 23, 2004
  2. Cyril Dex
    Replies:
    7
    Views:
    141,027
    sankalp.sawant59
    Mar 10, 2013
  3. Replies:
    3
    Views:
    894
    Andrew Thompson
    Feb 14, 2008
  4. Mozart
    Replies:
    7
    Views:
    3,809
  5. king

    create a batch file

    king, Oct 23, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    214
    Michele Dondi
    Oct 23, 2007
Loading...

Share This Page