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

Author Topic: need help with creating a log file from batch  (Read 20280 times)

0 Members and 1 Guest are viewing this topic.

Lwe

    Topic Starter


    Rookie

    need help with creating a log file from batch
    « on: March 25, 2011, 06:45:21 AM »
    Hi,
    i have this code:


    Quote
    @echo off
    color f0
    1) cls
    2) :menu
    3) cls
    4) echo -------------------------------------------------------------------------- >> log.txt
    5) echo ^|%date% -- %time%^|  >> log.txt
    6) echo -------------------------------------------------------------------------- >> log.txt
    7) script 2 >>log.txt
    8) echo.
    9) echo.


    i have 2 problems:
    lines 4-6 not apears when i run this bat.
    and when i had line 7 (most important) he gives me this error in a loop:
      The process cannot access the file because it is being used by another process.
    on the log.txt

    thanks!


    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: need help with creating a log file from batch
    « Reply #1 on: March 25, 2011, 11:16:07 AM »
    Lines 4-6 are being redirected to the log.txt file. Any output will be found there.

    Line 7 is executing a program/batch file named script. It wants to access to a file in use. Try booting the system and running your batch file when the system comes up ready. If the file is still busy, then script may require a system file or a file being used by your antivirus or some such. What does this program do?

    Good luck.  8)

    Please don't add line numbers to your scripts when posting. It only creates confusion.
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Lwe

      Topic Starter


      Rookie

      Re: need help with creating a log file from batch
      « Reply #2 on: March 26, 2011, 05:57:39 AM »
      Thanks.
      It ment to be a GUI.

      So i need to double anything that i want to add to the log?

      and is script 2 >>log.txt the right way to direct the errors to the log?

      if you can explain a bit more it would be great, because i am quite a noob.





       

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: need help with creating a log file from batch
      « Reply #3 on: March 26, 2011, 07:08:14 AM »
      So i need to double anything that i want to add to the log?

      Correct. You can send errors to one stream and non-errors to another stream, but you cannot send the same output to two different streams.

      and is script 2 >>log.txt the right way to direct the errors to the log?

      No. The interpreter will see the number two as a command line parameter for the script program/batchfile. Do not leave a space between the number two and the redirection symbols: script 2>>log.txt

      This page may help

      Good luck.  8)

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Lwe

        Topic Starter


        Rookie

        Re: need help with creating a log file from batch
        « Reply #4 on: March 26, 2011, 07:48:48 AM »
        Thank you.
        Sory, but im still cant manage to redirect the errors to a log file.
        i need to send errors after inputs.
        will it help you to see the all script?
        thank you for your help and time.

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: need help with creating a log file from batch
        « Reply #5 on: March 26, 2011, 09:18:08 AM »
        It might not be you. Redirection works when data is being sent to the STDOUT or STDERROR data streams. It may not be possible to redirect the data in your case.

        You can post your script if you wish (do not number the lines :P) but perhaps you can tell us more about this script program, what it does, is it part of a larger application, or where did it come from.

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Lwe

          Topic Starter


          Rookie

          Re: need help with creating a log file from batch
          « Reply #6 on: March 26, 2011, 11:02:49 AM »
          the script is not finished, so i will tell you that it a part of greater script.
          it needs to display a "menu" and than the user enter the number of the option from the menu and than:
          if menu=='number' goto :'function'

          Lwe

            Topic Starter


            Rookie

            Re: need help with creating a log file from batch
            « Reply #7 on: March 26, 2011, 12:29:17 PM »
            i'm sorry, but i dont understand.

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: need help with creating a log file from batch
            « Reply #8 on: March 26, 2011, 02:11:12 PM »
            Maybe I'm not understanding. The menu technique you describe has been used since DOS days. Based on your original post, line 7 seems to be a problem:

            Code: [Select]
            script 2 >>log.txt

            The interpreter sees the number 2 as a command line parameter to the script program. Based on your posts I understand that you want to send all error output from script to the log.txt file:

            Code: [Select]
            script 2>>log.txt

            That might work depending on the internals of whatever script is. You still haven't told us much, but if it is a program (.exe file), redirection simply may not work.

            Need more information.  8)
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            Lwe

              Topic Starter


              Rookie

              Re: need help with creating a log file from batch
              « Reply #9 on: March 26, 2011, 02:47:17 PM »
              Quote
              @echo off
              color f0
              :menu
              cls
              echo -------------------------------------------------------------------------- 
              echo ^|%date% -- %time%^|                     
              echo --------------------------------------------------------------------------
              echo.
              echo.
              echo ---------------
              echo Usual Procedure
              echo ---------------
              echo 1    Add hebrew Fonts.
              echo 2    Remove unwanted apps.
              echo 3    Edit prop.
              echo 4    Add ringtone.
              echo 5    Delete unwanted media.
              echo 6    Do all.
              echo --------------------------------------------------------------------------
              echo.
              set /p choice=
              if %choice%==1 (goto hebrew)
              if %choice%==2 (goto apps)
              if %choice%==3 (goto prop)
              if %choice%==4 (goto ringtone)
              if %choice%==5 (goto media)
              if %choice%==6 (goto all)

              :apps
              cd rom/system/app
              del com.htc.StockWidget.apk
              del com.htc.TwitterWidget.apk
              del com.htc.WeatherWidget.apk
              del Flickr.apk
              del htcbookmarkwidget.apk
              del HtcTwitter.apk
              del Maps.apk
              del Stk.apk
              del teeter.apk
              pause
              goto menu

              :prop
              cd rom/system
              build.prop
              pause
              goto menu






























              sorry i didnt post it first, this is the all script (in progress)
              is there a possible way to have a log file for this?


              thanks.

              ghostdog74



                Specialist

                Thanked: 27
                Re: need help with creating a log file from batch
                « Reply #10 on: March 27, 2011, 04:21:18 AM »
                i had a feeling Lwe is bill...

                Lwe

                  Topic Starter


                  Rookie

                  Re: need help with creating a log file from batch
                  « Reply #11 on: March 27, 2011, 06:06:47 AM »
                  what?

                  Sidewinder



                    Guru

                    Thanked: 139
                  • Experience: Familiar
                  • OS: Windows 10
                  Re: need help with creating a log file from batch
                  « Reply #12 on: March 27, 2011, 06:58:42 AM »
                  Quote
                  s there a possible way to have a log file for this?

                  Yes. Run the batch file as batchfile.bat 2>>log.txt. This should send all the errors to log.txt. Do not redirect the regular STDOUT stream to the log file (batchfile.bat >>log.txt) otherwise the menu will go unseen to the log file.

                  A few suggestions:

                  1. At the end of the menu selection block, insert an unconditional goto to redisplay the menu, otherwise the code will fall into the apps code if the user selects an invalid option.

                  Code: [Select]
                  .
                  .
                  .
                  if %choice%==5 (goto media)
                  if %choice%==6 (goto all)
                  goto menu

                  2. Indent your code to make it more readable. If you or someone else ever revisits the code, you'll be glad you did.

                  Code: [Select]
                  :prop
                    cd rom/system
                    build.prop
                    pause
                    goto menu

                  Good luck.  8)

                  i had a feeling Lwe is bill...

                  Perhaps, but I'm tired of chasing shadows and concerning myself with who's who. You almost need a telephone directory to keep it all straight. This is a public forum, perhaps we should just try to help with the questions and leave the paranoia to the psychiatrists.
                  The true sign of intelligence is not knowledge but imagination.

                  -- Albert Einstein

                  Lwe

                    Topic Starter


                    Rookie

                    Re: need help with creating a log file from batch
                    « Reply #13 on: March 27, 2011, 07:07:25 AM »
                    Thanks.
                    And ghostdog74 i will be glad if you wont tell me who i am, i am not this bill you talk about.

                    but what do you mean to run the batch file as batchfile.bat 2>>log.txt?
                    do i need to put it somewhere in the script?

                    Sidewinder



                      Guru

                      Thanked: 139
                    • Experience: Familiar
                    • OS: Windows 10
                    Re: need help with creating a log file from batch
                    « Reply #14 on: March 27, 2011, 07:49:51 AM »
                    but what do you mean to run the batch file as batchfile.bat 2>>log.txt?
                    do i need to put it somewhere in the script?

                    No. Type batchfile >>2.log.txt at the command prompt when you run the job. Be sure to replace batchfile with the actual name of your batch file.

                    Did you read the link I gave you about redirection? I also found this by the same author.

                     8)
                    The true sign of intelligence is not knowledge but imagination.

                    -- Albert Einstein