1.

Solve : Enable Batch File to Log Itself?

Answer»

I found this online:

Code: [Select]@REM *** START: Turns logging on ***
if "%~1" == "NOWLOGGING" goto NowLogging
set SchedulesLogFile=%TEMP%\%~n0 - %date:/=-% %time::=_%.txt
set SchedulesLogFile=%TEMP%\%~n0 - %RANDOM%.txt
set SchedulesLogFile=%TEMP%\%~n0.txt
%0 "NOWLOGGING" > "%SchedulesLogFile%" 2>&1
goto :EOF
:NowLogging
@REM *** END: Turns logging on ***
I don't call batch files like this so I'm wondering how to change this one so it starts like this:

Code: [Select]SET NOWLOGGING=yes
IF %NOWLOGGING%==yes.....

I've done this and tried using
Code: [Select]%0 >"%SchedulesLogFile%" 2>&1
but it's not working.

How should the above sample from the Internet be modified to run when the NOWLOGGING variable is set in the batch file itself?

Thanks,

MJNice to see I'm not the only one who's having trouble with this

Anyone?

MJQuote from: powlaz on March 26, 2014, 10:41:27 AM


I've done this and tried using
Code: [Select]%0 >"%SchedulesLogFile%" 2>&1
but it's not working.


Create a new batchfile called "logging.bat" and run that when you need to log it. The mybat.bat file can't be interactive because you won't see anything.

Code: [Select]@echo off
"c:\folder\mybat.bat" >"c:\folder\file.log" 2>&1

foxidrive - thanks. I've done it that way too. I've gotten used to not being able to see the script run, I'm OK with that. Can you help me make it work the way I described?

Ultimately when it is run the script will ask if I want to enable logging. If I enter "yes" it will set NOWLOGGING equal to "yes" and the script will kick off the logging command . . . if you can help me make it work when NOWLOGGING=yes.

Thanks,

MJI don't know anything about your batch file and there are any number of scenarios
that change the way it should be handled.

I want to use the command to troubleshoot new scripts. Generally I work with the script opened in NOTEPAD++, I run the script and modify as needed. I just want to tailor the commands so the script logs its activity without me having to call it from the command line.

My idea was to set a variable equal to "yes" at the TOP of the script. If this variable = "yes" then the script will log its activity to a text file that I can then look back over. If it is set to "no" the script will run as it was written to without logging itself.

I don't know of a better way to capture where a script hangs up that doesn't involve calling the script from the command prompt or another script. I'm open to suggestions but also could still use help modifying those commands.

Thanks,

MJQuote from: powlaz on APRIL 08, 2014, 06:53:29 AM
I don't know of a better way to capture where a script hangs up that doesn't involve calling the script from the command prompt or another script.

I generally use echo statements to track the changes along with pause statements. That's the most friendly debugging that I know of.
My file manager gives me an instant command line and enhanced access to launching and editing, which helps too.

Does notepad++ allow you to call the batch code in DIFFERENT ways?


Discussion

No Comment Found