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 20290 times)

0 Members and 1 Guest are viewing this topic.

Lwe

    Topic Starter


    Rookie

    Re: need help with creating a log file from batch
    « Reply #15 on: March 27, 2011, 07:59:49 AM »
    i saw a script that there is that command on the script and it worked.
    it was: script 0 2>>log.txt

    i want it all to be on one script, not to write in the command prompt.
    there isn't a way?

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: need help with creating a log file from batch
    « Reply #16 on: March 27, 2011, 09:02:03 AM »
    There is a definite failure to communicate.

    Nobody is suggesting you write the script at the command prompt (although you can). Use an editor (notepad will work) to write your script (batch file); save it with any name you like but with a bat extension. Open up a command window, navigate to the directory where you saved your script/batch file and run using the name you saved the script with and redirecting the error output to the log.txt file:

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

    I'm not sure what this is all about:

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

    but the zero is passed as a command line parameter which is not referenced in your script and therefore servers no purpose. This piece of the command 2>>log.txt sends the error stream to the log file.

    Have you even tried to run your batch file. Even if incomplete, it's a good idea to at least find any syntax errors and maybe even some logic errors. You've written the logic for menu selections 2 and 3, so test with them and see the results yourself. Better to test as you write rather than wait until the script is 'finished' and then have to slog through all the errors at once.

     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 #17 on: March 27, 2011, 09:37:31 AM »
      Of course i have tested it, with a lot of situation.
      But will this method 'remmember' all the errors that the script had on run?

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: need help with creating a log file from batch
      « Reply #18 on: March 27, 2011, 11:17:02 AM »
      Of course i have tested it, with a lot of situation.
      But will this method 'remmember' all the errors that the script had on run?

      I thought that was the whole point of the log file. Have you checked the contents? If the file is empty after running your batch file, then all is well in Wonderland. If not, you need to backtrack and see where the error came from and how to fix it.

      As I already mentioned, one defensive piece of code is the unconditional goto you could insert after checking for valid menu selections. Another would be to check if each of the files exists before trying to delete them.

      Why is it even necessary to 'remember' the errors? Why not just let them appear on the console, and then fix the code to prevent them?  Keeping it simple makes it easier to fix things later.

      If you're still having problems, post the name of your batch file and we can discuss exactly how to run from the command prompt. In the meantime I need an adult beverage.  ;D



      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 #19 on: March 27, 2011, 11:34:18 AM »
        lol.
        thanks alot!