Dogway Posted February 7, 2013 Posted February 7, 2013 (edited) HelloI'm trying to add a log export ability to my Run on first boot batch file after an XP silent installation. I want to know if everything went fine (or not) so I can tweak further and for reference as well.I really don't understand batch much, not at least at this level. I found this example that renders out everything shown in the console window, which is fine, but in return now the console is blank.@ECHO ONcall :Logit>>C:\mylog.log 2>&1exit /b 0:Logit::Your bat code hereThen the following code examples IIRC were the opposite, show everything on the console and log only the commands you attach /log flag to.That's what I tried, but I got no log. Do I need to add something else somewhere, what am I missing?@echo offif /I ?%1? NEQ ?/log? goto :LogItset LogCmd=%*echo oncall %0 %LogCmd:/log=% >"%~dpn0.log" 2>&1set LogCmd=goto :eof:LogItREM the start of your batch fileThank you! Edited February 7, 2013 by Dogway
Guest Posted February 7, 2013 Posted February 7, 2013 Try changing the following line:if /I ?%1? NEQ ?/log? goto :LogIt...to this...if /I not "%~1"=="/log" goto :LogIt
Dogway Posted February 7, 2013 Author Posted February 7, 2013 I changed the line but nothing happens. I have the log code first, then the variables, then the below command.%ENCODER% --level 4.1 --preset %PRESET% --tune %TUNE% --pass 1 --bitrate %BITRATE% --stats "%STATS%" --me %ME% --deblock -2:-1 --keyint %KEY% --min-keyint %MKEY% --frames %FRAMES% --demuxer %DEMUX% --vbv-bufsize 24000 --no-fast-pskip --sar %SAR% --aq-strength 1.2 --vbv-maxrate 24000 --fps %FPS% --output NUL "%INPUT%" /log
Yzöwl Posted February 7, 2013 Posted February 7, 2013 I would suggest something along these lines:MyScript.cmd@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONSET "_OUT=CALL :SUB"FOR /F "DELIMS=/-" %%# IN ("%*") DO ( IF /I %%# EQU L SET "_OUT=(%_OUT%)>MYLOG.LOG 2>&1")%_OUT%GOTO :EOF:SUB your command(s) hereThis means that your script will accept L, l, /L, /l, -L or -l as parameters for logging the output to file. anything else should log the output to the console window.for this to work your script should have no spaces in its file name or at least be quoted
jaclaz Posted February 7, 2013 Posted February 7, 2013 You might be interested in a TEE command :http://www.robvanderwoude.com/unixports.phpjaclaz
Dogway Posted February 7, 2013 Author Posted February 7, 2013 Thanks a lot Yzöwl, but again no log is output, here is my script, did I miss something? (edit: my bat is called hey.bat so no spaces)@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONSET "_OUT=CALL :SUB"FOR /F "DELIMS=/-" %%# IN ("%*") DO ( IF /I %%# EQU L SET "_OUT=(%_OUT%)>MYLOG.LOG 2>&1")%_OUT%GOTO :EOF:SUB::Your bat code hereD:\Programas\VIDEO\x264-2245.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL Copia.avs /Ljaclaz, that's a bit over my head, at least for the time being, I don't discard to have a deeper look later on.
Yzöwl Posted February 7, 2013 Posted February 7, 2013 You are supposed to run my batch script, MyScript.cmd with or without the parameter, not your command within the script!examplesMyScriptorMyScript -l
Dogway Posted February 7, 2013 Author Posted February 7, 2013 I see I was quite confused!Now I usedhey.cmd -LAnd yes I get the log, but console is blank
Yzöwl Posted February 7, 2013 Posted February 7, 2013 that is because you asked for the information to be output to a file.If you want it to be logged to two places simultaneously then you need to tee it, as jaclaz has already indicated.You can either use a 3rd party utility for that purpose or possibly this vbscript.tee.vbsset con = createobject("scripting.filesystemobject").opentextfile("con:", 2)do until wsh.stdin.atendofstream s = wsh.stdin.readline wsh.echo s : con.writeline s loopto use it you'd probably just pipe your script into it.hey.cmd@D:\Programas\VIDEO\x264-2245.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL Copia.avsThen run it like this:hey.cmd | cscript tee.vbs >mylog.log
Dogway Posted February 7, 2013 Author Posted February 7, 2013 (edited) Woow, indeed I'm not asking something easy. Thanks a bunch for the help, the log is blank, well I get this:Microsoft (R) Windows Script Host versi¢n 5.7Copyright (C) Microsoft Corporation 1996-2006. Reservados todos los derechos.but I see the point.Yes, the title is misleading but in my OP I made clear I wanted to output to both, console and log, at the same time.EDIT:Now I'm using jaclaz's suggestion. In the same vein:Downloaded Tee.bat and make the call as:hey.cmd ¦ TEE.BAT [ -a ] C:\OEM\mylog.logbut I don't get any log. Should be the bat encoded in some format? different from ANSI? is the ¦ character fine. Edited February 7, 2013 by Dogway
Dogway Posted February 9, 2013 Author Posted February 9, 2013 Ok, for the second alternative (using TEE.BAT) I managed to output something.I had to add > before the log filename, and also remove the @ before the command in the bat file.But, all I get in the log is the question, my input command:D:\Programas\VIDEO\x264-2245.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL Copia.avsand not my answer (or Q&A together):C:\OEM>D:\Programas\VIDEO\x264-2245.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL Copia.avs avs [info]: 720x480p 0:0 @ 30000/1001 fps (cfr)x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64x264 [info]: profile Main, level 4.1[1.0%] 1/101 frames, 1.10 fps, 2075.60 kb/s, eta 0:01:30 [14.9%] 15/101 frames, 12.98 fps, 1109.24 kb/s, eta 0:00:06 [34.7%] 35/101 frames, 24.89 fps, 1600.93 kb/s, eta 0:00:02 [74.3%] 75/101 frames, 45.29 fps, 1476.59 kb/s, eta 0:00:00 x264 [info]: frame I:1 Avg QP:21.54 size: 8657x264 [info]: frame P:29 Avg QP:18.16 size: 9658x264 [info]: frame B:71 Avg QP:18.83 size: 4739x264 [info]: consecutive B-frames: 2.0% 2.0% 32.7% 63.4%x264 [info]: mb I I16..4: 87.7% 0.0% 12.3%x264 [info]: mb P I16..4: 59.9% 0.0% 0.0% P16..4: 32.6% 0.0% 0.0% 0.0% 0.0% skip: 7.6%x264 [info]: mb B I16..4: 18.1% 0.0% 0.0% B16..8: 31.6% 0.0% 0.0% direct:29.6% skip:20.7% L0:42.6% L1:43.7% BI:13.7%x264 [info]: final ratefactor: 18.81x264 [info]: direct mvs spatial:97.2% temporal:2.8%x264 [info]: coded y,uvDC,uvAC intra: 45.7% 62.9% 8.7% inter: 19.3% 46.7% 0.5%x264 [info]: i16 v,h,dc,p: 37% 28% 28% 7%x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 23% 24% 7% 6% 4% 8% 5% 12%x264 [info]: i8c dc,h,v,p: 53% 23% 23% 2%x264 [info]: Weighted P-Frames: Y:0.0% UV:0.0%x264 [info]: kb/s:1484.21encoded 101 frames, 56.20 fps, 1484.21 kb/s
allen2 Posted February 9, 2013 Posted February 9, 2013 (edited) x264 encoder use the error channel for its normal output so if you need to log its output, you'll need to add "1>NUL 2>%temp%\x264_encoding.log" for example to the line launching it.For the second point as you need the output in the console and in the log file, you could try to launch x264 with log (as explained before) as background process and then print the log with "tail -f" (from the unix tools).So something like this will work:start /B /separate "encoding" x264.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL Copia.avs 1>NUL 2>%temp%\log_x264.logtail.exe -f %temp%\log_x264.logAs tail -f will wait forever, and as the --pid option doesn't work in this dos port (and some newer mingw32 port), you'll have to interrupt it with a control+C after its ending or kill tail process. This lastest option might be automated if you don't run many x264 process at the same time as batch doesn't provide any simple way of getting the pid of a launched process.Edit1: as a side note, doing this with a higher programming language (C++, VB, vbs, autoit ....) will be a lot easier.Edit2:In batch using third party tools - unix tools sleep, tail, gawk, wc and sysinternals handle -, i was able to make it work:@echo offstart /B /separate "encoding" x264.exe --level 4.1 --preset slower --tune film --pass 1 --bitrate 1500 --deblock -2:-1 --keyint 300 --min-keyint 30 --aq-strength 1.2 --fps 29.970 --output NUL E:\encodage\dimitri.avs 1>NUL 2>%temp%\log_x264.logstart /B /separate "logging" d:\utils\command\tail.exe -f %temp%\log_x264.logsetlocal:waitset ended=0for /f "usebackq" %%i in (`handle %temp%\log_x264.log ^|findstr /i "pid:" ^|wc -l`) do (if "%%i"=="1" set ended=1)if "%ended%"=="1" goto killpidsleep 1goto wait:killpidhandle %temp%\log_x264.log |findstr /i "pid:" |gawk -F"pid:" "{print $2}" |gawk "{print $1}" >%temp%\tail_pid.txtfor /F %%i in (%temp%\tail_pid.txt) do (taskkill /pid %%i /t /f >NUL):endendlocalpause Edited February 9, 2013 by allen2
Dogway Posted February 9, 2013 Author Posted February 9, 2013 (edited) Wonderful, this almost feel like hacking!I think using x264 wasn't the best example since it's only for my tests. I will use the logging for the "Install at first Boot" batch of an OS install, so I don't think I will have the described problems.Most likely I will get along with the TEE.BAT route.I also used your first example with tail.exe. It exported the answer (error log), I guess this is all I want to know (discarding the call line). Also I can anyways run a kill process command for tail.exe.So I should always append the next for any of my commands right?start /B /separate (mycommands+flags) 1>NUL 2>%temp%\log_x264.logstart /B /separate (mycommands+flags) 1>NUL 2>%temp%\log_x264.logstart /B /separate (mycommands+flags) 1>NUL 2>%temp%\log_x264.log...I couldn't run your second example, I got a BSOD and it scared the hell out of me. I think with all these example it's more than enough. Edited February 9, 2013 by Dogway
jaclaz Posted February 9, 2013 Posted February 9, 2013 So I should always append the next for any of my commands right?No.You need to understand redirection (and the concepts of "standard output" and "standard error" first:http://www.robvanderwoude.com/redirection.phpEvery program might "decide" to write *something* to standard output and *something else* to standard error, so you should append BOTH standard output and standard error to the log:command >> file 2>&1jaclaz
Dogway Posted February 9, 2013 Author Posted February 9, 2013 I see.This?start /B /separate (mycommands+flags) >> %temp%\log_x264.log 2>&1start /B /separate (mycommands+flags) >> %temp%\log_x264.log 2>&1...I guess it was ignoring call line because I was writing 1>NUL
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now