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

Author Topic: catch error  (Read 12436 times)

0 Members and 1 Guest are viewing this topic.

vasblr

    Topic Starter


    Starter

    catch error
    « on: March 05, 2009, 05:31:54 AM »
    Hi
    I was new to MSDos, my question is i want to catch the error message to a variable\to a .txt file

    Example:
    i want to rename file which doesnot in the dir, DOS threw an error, i want to catch that error and its DOS error code in to variable

    macdad-



      Expert

      Thanked: 40
      Re: catch error
      « Reply #1 on: March 05, 2009, 06:11:52 AM »
      Code: [Select]
      if ERRORLEVEL 2
      (
      set return=%errorlevel%
      )

      Will this do?
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      devcom



        Apprentice

        Thanked: 37
        Re: catch error
        « Reply #2 on: March 05, 2009, 07:30:01 AM »
        Code: [Select]
        dir ZX:\ 2>File.txt
        for /f "tokens=1*" %%a in (File.txt) do echo %%a
        pause

        yes drive ZX will not exist just for example
        Download: Choice.exe

        vasblr

          Topic Starter


          Starter

          Re: catch error
          « Reply #3 on: March 05, 2009, 10:25:01 PM »
          thank you for help !!! its working  :D

          i want to catch all types of errors

          here comes.. i am running a batch file script in batch file is a below
          ----------------------------------------------------------------------------------------------
          REM Starts JOB (jobID 1)
          "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -S HDBLVTXDEAM4271-E -Q "EXEC Account.dbo.PROC_Fetch_Details_Start 1"

          ----------------------------------------------------------------------------------------------

          i am running thru SQL server , here for first time job runs it was success (capture success) , in second run as the job was already running , it should thru error (capture the error message, append to the existing log file)

          is it possible to capture all the error\success MSG in one log file??..

          vasblr

            Topic Starter


            Starter

            Re: catch error
            « Reply #4 on: March 06, 2009, 03:55:22 AM »
            i got the solution to catch the msg..  :D to a text file only on failure :(
            ----------------------------------------------------------------------------------------------
            echo.-- %Date% %Time% -- >>c:\logfile.txt
            REM Starts JOB (jobID 1)
            "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -S HDBLVTXDEAM4271-E -Q "EXEC Account.dbo.PROC_Fetch_Details_Start 1">>c:\logfile.txt
            ----------------------------------------------------------------------------------------------

            small problem.. i can't catch the success of the batchfile as of now with the above statement i can catch only if there is any failure of the script\interalerrors
            on scuccess log shows as below
            ------------------------------------------
            -- Fri 03/06/2009 15:16:23.84 --
            ------------------------------------------

            Please help me if i can capture success  ???

            macdad-



              Expert

              Thanked: 40
              Re: catch error
              « Reply #5 on: March 06, 2009, 06:17:38 AM »
              if you want to capture success then try this:

              Code: [Select]
              if ERRORLEVEL==0
              (
              set return=%errorlevel%
              )

              that will capture it on success
              and here's a complete list of all the errorlevel codes: http://www.computerhope.com/xdoseror.htm
              If you dont know DOS, you dont know Windows...

              Thats why Bill Gates created the Windows NT Family.

              Reno



                Hopeful
              • Thanked: 32
                Re: catch error
                « Reply #6 on: March 06, 2009, 07:50:06 AM »
                are you sure sqlcmd.exe give some message when run successfully? try running sqlcmd.exe without redirecting it to file, and see if it gives message on success.

                if it doesnt output message when success, you can manually echo it:
                Code: [Select]
                ("C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -S HDBLVTXDEAM4271-E -Q "EXEC Account.dbo.PROC_Fetch_Details_Start 1" && echo sqlcmd.exe success)>>c:\logfile.txt 2>>&1

                vasblr

                  Topic Starter


                  Starter

                  Re: catch error
                  « Reply #7 on: March 09, 2009, 03:06:46 AM »
                  Thanks all, for help.  :D, i got the required result.

                  macdad-



                    Expert

                    Thanked: 40
                    Re: catch error
                    « Reply #8 on: March 09, 2009, 06:55:33 AM »
                    glad to hear it  ;)
                    If you dont know DOS, you dont know Windows...

                    Thats why Bill Gates created the Windows NT Family.