Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: DOS batch file - not recognized as an internal command ...  (Read 22200 times)

0 Members and 1 Guest are viewing this topic.

Oldtooth

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    DOS batch file - not recognized as an internal command ...
    « on: June 16, 2011, 09:00:11 PM »
    Hello Everybody,
    This is my first post in this forum.
    Would really appreciate someone's help on my DOS batch file below.
    I'm fairly clueless on DOS batch scripts (as you can probably see).
    The script is called extract_booking, and it's supposed to do the following:
    Firstly check the input folder to see if there are any gunzip files to process (.tar.gz) - if not then exit.
    Secondly, uncompress the files in 2 steps using the 7-zip command line application.
    (Step one goes from .gz to .tar, step two goes from .tar to text file format).
    The uncompressing is performed inside a FOR IN DO loop in the case of multiple files.
    After the extraction is complete, then some housekeeping is done.
    When I run the script from the DOS command line, I get the error message:
    'extract_booking' is not recognized as an internal or external command, operable program or batch file".
    Can anyone see where I'm going wrong please?


    @echo off

    REM Check to see if the input folder is empty

    cd d:\fromdoka\files\

    dir %1|find " 0 File(s)" > NUL
    if errorlevel 1 goto Extract
    dir %1| find " 2 Dir(s)" > NUL
    if errorlevel 1 goto Extract
    echo No Booking Files Pending
    goto end

    :Extract
    set ddir=D:\FromDoka\Files\
    REM ddir is the download directory for transactions
    REM tdir is the output directory where the GZ files will be extracted to TAR files
    set tdir=D:\FromDoka\1_Tar_Files\
    REM gdir is the output directory where the TAR files will be extracted to GLE files
    set gdir=D:\FromDoka\2_GLE_Files\
    REM Here is the loop for processing multiple booking files
    for %%file in (.\*.gz) do (
    7za.exe e %ddir% -o%tdir% -aoa
    ECHO Waiting 3 seconds
    PING 1.1.1.1 -n 1 -w 3000 >NUL
    7za.exe e %tdir% -o%gdir% -aoa
    )

    :Housekeeping

    move /y %ddir%\*.gz d:\fromdoka\3_gz_archives\
    REM switch y overwrites existing files without prompting
    copy /y d:\fromdoka\2_GLE_Files\*.gle "c:\Program Files\MeridianEBanking\FromDOKA\Staging_Files\"
    move /y d:\fromdoka\2_GLE_Files\*.* d:\fromdoka\4_GLE_Archives\
    del d:\fromdoka\1_Tar_Files\*.*

    :end

    Linux711



      Mentor

      Thanked: 59
      • Yes
      • Programming Blog
    • Certifications: List
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: DOS batch file - not recognized as an internal command ...
    « Reply #1 on: June 16, 2011, 10:15:15 PM »
    I don't think I know enough to fully answer your question, but I just noticed that you were exploiting the ping command in order to wait 3 seconds.

    You can try this: http://www.computerhope.com/download/utility/sleep.exe

    EDIT:
    Quote
    know enough

    Lazy
    YouTube

    "Genius is persistence, not brain power." - Me

    "Insomnia is just a byproduct of, "It can't be done"" - LaVolpe

    Salmon Trout

    • Guest
    Re: DOS batch file - not recognized as an internal command ...
    « Reply #2 on: June 17, 2011, 12:05:31 AM »
    'extract_booking' is not recognized as an internal or external command, operable program or batch file".

    Quote
    Can anyone see where I'm going wrong please?

    It sounds like you are trying to run the batch script from a different folder (than the one it is located in). Default command prompt behaviour is to show the current folder drive/path as the prompt, with a > sign after it. Like this:

    C:\>
    C:\Users\Jim>

    etc

    If you want to start a batch file by typing its bare name (no drive or path) then you have to be in the same folder.  If not, then you must type the full path as well, or else put the batch file in a folder listed in the PATH variable.


    Oldtooth

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: DOS batch file - not recognized as an internal command ...
      « Reply #3 on: June 17, 2011, 12:35:57 AM »
      Thanks Salmon Trout,
      I placed the bat file in the c:\winnt folder, and reran it.
      The "Internal Command" error has gone, but instead I received a different error:

      %file was unexpected at this time.

      Is there something wrong with my FOR loop I wonder?

      Salmon Trout

      • Guest
      Re: DOS batch file - not recognized as an internal command ...
      « Reply #4 on: June 17, 2011, 01:08:27 AM »
      %file was unexpected at this time.
      Is there something wrong with my FOR loop I wonder?

      FOR variables, (technically "metavariables"), the ones with 2 percent signs in front, are single letters only, so change %%file to something else, e.g. %%f or %%F (case does matter and needs to match wherever the variable is created and/or used). But still you ain't going anywhere just yet. I don't see the loop variable being used anywhere within the loop, so nothing is going to get done. It looks like you are coming to batch scripting from some other language? Also, I see some odd things in that "loop" - you seem to be extracting twice? Could you talk me through or use REMs to show what you are intending to do?

      « Last Edit: June 17, 2011, 01:46:04 AM by Salmon Trout »

      Oldtooth

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: DOS batch file - not recognized as an internal command ...
        « Reply #5 on: June 17, 2011, 03:20:50 AM »
        Hi Salmon Trout,
        Yes you're right - I've got a SQL n COBOL background, and know very little about DOS batch scripting.
        So apologies for making elementary mistakes.

        Here's the script again, after a few suggested changes and incorporating some REM's:

        @echo off

        REM Check to see if the input folder is empty

        cd d:\fromdoka\files\

        dir %1|find " 0 File(s)" > NUL
        if errorlevel 1 goto Extract
        dir %1| find " 2 Dir(s)" > NUL
        if errorlevel 1 goto Extract
        echo No Booking Files Pending
        goto end

        :Extract
        cd d:\fromdoka\scripts\
        REM In the folder above, there may be none, 1, or more archive files in .tar.gz format
        REM My intention is to extract the underlying text file, copy it to another folder, and
        REM do some housekeeping.
        REM All of this should be done automatically, in a Windows scheduled task.
        REM On my Windows 2000 machine, I have installed 7-Zip to do the extracting, but the problem
        REM is that 7-zip won't do it in one step, it needs 2 steps
        REM First is extract .gz to .tar  Second is extract text file from .tar
        REM So the iteration should process one .gz file at a time
        REM I cant find any other command line applic to do the extracting in one step on Win2k


        REM ddir is the download directory for the transactions
        REM tdir is the output directory where the GZ files will be extracted to TAR files
        set tdir=D:\FromDoka\1_Tar_Files\
        REM gdir is the output directory where the TAR files will be extracted to GLE text files
        set gdir=D:\FromDoka\2_GLE_Files\
        REM zdir is the directory where the executables are kept
        set zdir=D:\FromDoka\Scripts\


        REM Here is the loop for processing multiple booking files
        for %%f in (%ddir%\*.gz) do (
        %zdir%\7za.exe e %ddir%\%%f -o%tdir% -aoa
        ECHO Waiting 3 seconds to ensure the first step is completed
        PING 1.1.1.1 -n 1 -w 3000 >NUL
        %zdir%\7za.exe e %tdir%\%%f -o%gdir% -aoa
        )

        :Housekeeping

        move /y %ddir%\*.gz d:\fromdoka\3_gz_archives\

        REM switch y overwrites existing files without prompting

        REM copy /y d:\fromdoka\2_GLE_Files\*.gle "c:\Program Files\MeridianEBanking\FromDOKA\Staging_Files\"
        move /y d:\fromdoka\2_GLE_Files\*.* d:\fromdoka\4_GLE_Archives\
        del d:\fromdoka\1_Tar_Files\*.*

        :end

        When I run the batch file I get the same error as before - file not recognized as an internal command .....

        Salmon Trout

        • Guest
        Re: DOS batch file - not recognized as an internal command ...
        « Reply #6 on: June 17, 2011, 03:27:48 AM »
        can you post the exact error message you are getting, by copying and pasting from the command prompt window, including in the copy the prompt and what you typed?

        like this?

        Code: [Select]
        C:\Users\Me>notexist
        'notexist' is not recognized as an internal or external command,
        operable program or batch file.

        C:\Users\Me>

        Oldtooth

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: DOS batch file - not recognized as an internal command ...
          « Reply #7 on: June 17, 2011, 04:03:04 AM »
          I forgot to update the script in the C:\winnt folder.
          So now when I run it, I get a differrent error:


          D:\FromDoka\Scripts>
          D:\FromDoka\Scripts>extract_bookings
          A duplicate file name exists, or the file
          cannot be found.
          The filename, directory name, or volume label syntax is incorrect.
          d:\fromdoka\1_Tar_Files\*.*, Are you sure (Y/N)? n
          D:\FromDoka\Scripts>

          Salmon Trout

          • Guest
          Re: DOS batch file - not recognized as an internal command ...
          « Reply #8 on: June 17, 2011, 06:24:15 AM »
          I think we'll be proceeding in an incremental manner...

          Where exactly are you setting the value of the variable %ddir%?

          Oldtooth

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Unknown
            Re: DOS batch file - not recognized as an internal command ...
            « Reply #9 on: June 17, 2011, 08:34:39 AM »
            Thanks, I appreciate your patience Salmon.

            Looks like I accidentally deleted the line that assigns the value for ddir.
            I've re-inserted it above the "set tdir" line .....

            ...
            REM tdir is the output directory where the GZ files will be extracted to TAR files
            set ddir=D:\FromDoka\Files
            set tdir=D:\FromDoka\1_Tar_Files\
            ...

            When I run the script again, the result (with one GZ file waiting in the folder D:\FromDoka\Files\) is:

            D:\FromDoka\Scripts>extract_bookings

            7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


            Error:
            cannot find archive
            Waiting 3 seconds to ensure the first step is completed

            7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


            Error:
            cannot find archive
            D:\FromDoka\Files\20110530-090313-zert-buchungen-sgs-doka.tar.gz
            The filename, directory name, or volume label syntax is incorrect.
            d:\fromdoka\1_Tar_Files\*.*, Are you sure (Y/N)? n
            D:\FromDoka\Scripts>


            Salmon Trout

            • Guest
            Re: DOS batch file - not recognized as an internal command ...
            « Reply #10 on: June 17, 2011, 10:18:12 AM »
            I suggest you replace the loop part of your script with the following which will at least provide some diagnostic messages.

            Code: [Select]
            for %%f in (%ddir%\*.gz) do (
            echo Diagnostic message [1]
            echo Extracting from "%%~dpnxF"
            REM THis MAY work - you are trying to extract from %%f which is each .gz file in ddir in turn
            echo 1. Executing %zdir%\7za.exe e "%%~dpnxf" -o%tdir% -aoa
            %zdir%\7za.exe e "%%~dpnxf" -o%tdir% -aoa
            echo.
            ECHO Waiting 3 seconds to ensure the first step is completed
            PING 1.1.1.1 -n 1 -w 3000 >NUL
            echo.
            Echo Diagnostic message [2]
            echo Extracting from "%%~dpnxf"
            REM This SHOULD NOT WORK because FOR is processing a LIST OF GZ FILES IN ddir
            Echo 2. Executing %zdir%\7za.exe e "%%~dpnxF" -o%gdir% -aoa
            %zdir%\7za.exe e "%%~dpnxF" -o%gdir% -aoa
            )
            « Last Edit: June 17, 2011, 01:27:20 PM by Fed »

            Oldtooth

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Unknown
              Re: DOS batch file - not recognized as an internal command ...
              « Reply #11 on: June 18, 2011, 07:09:43 AM »
              Sadly, I have had no VPN connection to my network all day - so I will try your suggestion tomorrow.

              Oldtooth

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Unknown
                Re: DOS batch file - not recognized as an internal command ...
                « Reply #12 on: June 18, 2011, 10:28:48 PM »
                This looks very useful Salmon.
                I can see where the problem lies (though I'm not sure how to fix it).
                First, here's the output from your diagnostic routine ..

                D:\FromDoka\Scripts>extract_bookings
                Diagnostic message [1]
                Extracting from "%~dpnxF"
                1. Executing D:\FromDoka\Scripts\\7za.exe e "D:\FromDoka\Files\20110530-090313-z
                ert-buchungen-sgs-doka.tar.gz" -oD:\FromDoka\1_Tar_Files\ -aoa

                7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

                Processing archive: D:\FromDoka\Files\20110530-090313-zert-buchungen-sgs-doka.ta
                r.gz

                Extracting  20110530-zert-buchungen-sgs-doka.tar

                Everything is Ok

                Size:       4096
                Compressed: 524

                Waiting 3 seconds to ensure the first step is completed

                Diagnostic message [2]
                Extracting from "D:\FromDoka\Files\20110530-090313-zert-buchungen-sgs-doka.tar.g
                z"
                2. Executing D:\FromDoka\Scripts\\7za.exe e "%~dpnxF" -oD:\FromDoka\2_GLE_Files\
                 -aoa

                7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


                Error:
                cannot find archive
                D:\FromDoka\Files\20110530-090313-zert-buchungen-sgs-doka.tar.gz
                The filename, directory name, or volume label syntax is incorrect.
                d:\fromdoka\1_Tar_Files\*.*, Are you sure (Y/N)? n
                D:\FromDoka\Scripts>

                --------------------------------------------
                The extraction is a two step process:  step one uses the original filename, which has a .tar.gz extension, and produces a .tar file, placing it in the tdir directory.
                But step two should use the extracted filename (in the tdir directory), with the .tar extension, rather than the original .tar.gz filename to complete the second part of the extraction.
                Tricky.
                How can I reference the .tar file in the extraction process?



                Salmon Trout

                • Guest
                Re: DOS batch file - not recognized as an internal command ...
                « Reply #13 on: June 19, 2011, 01:51:25 AM »
                Your problem is that you are trying to make one FOR command do the work of two. FOR processes a list of items specified by what is in the dataset thus:

                FOR %%V in (dataset) do bla bla bla

                or

                FOR %%V in (dataset) do (
                    bla bla bla
                    bla bla bla
                    )

                In your original code the dataset is (%ddir%\*.gz). This means that FOR will make a list of files matching that spec and then perform the same operation on each in turn. In your case that is supply the filename to 7za.exe along with some parameters. That is all. If I understand you correctly, this will put some .tar files in %tdir%. If you then want to extract everything from the .tar files in %tdir% you will need a second loop. Also since a batch script will not execute a line until the previous one has finished, you don't have to wait 3 seconds (or any time at all)

                So try this in place of your loop... You can remove the "Press a key " and "Pause > nul" lines when you are happy with it.

                Code: [Select]
                echo Stage [1]
                echo Extracting from each .gz file in folder   : %ddir%
                echo The extracted files will appear in folder : %tdir%
                echo Files to work on:
                echo.
                dir /b %ddir%\*.gz
                echo.
                echo Press a key when you are ready...
                Pause > nul
                echo.
                echo Starting stage [1]
                for %%A in (%ddir%\*.gz) do %zdir%\7za.exe e "%%~dpnxA" -o%tdir% -aoa
                echo.
                echo Finished stage [1]
                echo.
                echo Stage [2]
                echo Extracting from each .tar file in folder  : %tdir%
                echo The extracted files will appear in folder : %gdir%
                echo Files to work on:
                echo.
                dir /b %tdir%\*.tar
                echo.
                echo Press a key when you are ready...
                Pause > nul
                echo.
                echo Starting stage [2]
                for %%B in (%tdir%\*.tar) do %zdir%\7za.exe e "%%~dpnxB" -o%gdir% -aoa
                echo.
                echo Finished stage [2]
                echo.
                echo Files extracted to %gdir%:
                echo.
                dir /b %gdir%
                echo.
                echo Press a key to finish...
                Pause > nul
                echo.


                Oldtooth

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Unknown
                  Re: DOS batch file - not recognized as an internal command ...
                  « Reply #14 on: June 20, 2011, 12:27:49 AM »
                  Wow - Salmon you're terrific. The batch script works perfectly now.
                  Your diagnostic skills are to be applauded. I certainly got a lesson from the master.
                  Many thanks for your help.