Page 1 of 1
Saving a changing output to a text file... and update the file each time output changes!
Posted: 09 Sep 2017 21:31
by Kvc
Talking about the wget.exe - which allows to download the stuff from command-line interface. it displays the current download position / value on console window. But, I want to read it via a file without displaying it (can use -q, but it won't give me current download position)
Can anyone help?
wget link:
http://gnuwin32.sourceforge.net/packages/wget.htm
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 10 Sep 2017 07:47
by aGerman
Did you already redirect the output to a text file and did you observe the content using a HEX editor? I assume that the percentage wil be updated using backspace and/or carriage return characters.
You could put such a text file in a ZIP archive and upload it here.
Steffen
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 11 Sep 2017 19:25
by Kvc
aGerman wrote:Did you already redirect the output to a text file and did you observe the content using a HEX editor?
I tried to simply redirect the Command's output in a simple text file as:
But, the problem is that... it is still showing the output on the console with all those %ages and the file a.txt is of 0 bytes - even afte the process completes. No update at all.
kvc
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 12 Sep 2017 01:19
by aGerman
Sounds like Wget writes to the StdErr stream.
Try...
...where StdOut and StdErr are merged and redirected to the file. If you only need to redirect the StdErr use ...
...instead.
Steffen
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 13 Sep 2017 08:34
by Kvc
aGerman wrote:Sounds like Wget writes to the StdErr stream.
Wow, Amazing! After applying this change i've got the whole log of the download process in the text file. Really great help.
Code: Select all
--2017-09-13 19:58:57-- http://download1495.mediafireuserdownload.com/1kx7aj06qbjg/uzyj5151a66gne9/Batch-Store+v.1.0+By+Kvc.zip
Resolving download1495.mediafireuserdownload.com (download1495.mediafireuserdownload.com)... 205.196.123.183
Connecting to download1495.mediafireuserdownload.com (download1495.mediafireuserdownload.com)|205.196.123.183|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8137333 (7.8M) [application/zip]
Saving to: 'Batch-Store+v.1.0+By+Kvc.zip'
0K .......... .......... .......... .......... .......... 0% 54.8K 2m24s
50K .......... .......... .......... .......... .......... 1% 129K 1m42s
100K .......... .......... .......... .......... .......... 1% 163K 83s
150K .......... .......... .......... .......... .......... 2% 157K 75s
200K .......... .......... .......... .......... .......... 3% 194K 67s
250K .......... .......... .......... .......... .......... 3% 197K 62s
300K .......... .......... .......... .......... .......... 4% 228K 58s
350K .......... .......... .......... .......... .......... 5% 222K 54s
400K .......... .......... .......... .......... .......... 5% 200K 52s
450K .......... .......... .......... .......... .......... 6% 285K 49s
500K .......... .......... .......... .......... .......... 6% 168K 48s
550K .......... .......... .......... .......... .......... 7% 345K 46s
600K .......... .......... .......... .......... .......... 8% 181K 45s
650K .......... .......... .......... .......... .......... 8% 202K 44s
700K .......... .......... .......... .......... .......... 9% 289K 43s
750K .......... .......... .......... .......... .......... 10% 235K 42s
800K .......... .......... .......... .......... .......... 10% 302K 40s
850K .......... .......... .......... .......... .......... 11% 290K 39s
900K .......... .......... .......... .......... .......... 11% 280K 38s
950K .......... .......... .......... .......... .......... 12% 294K 37s
1000K .......... .......... .......... .......... .......... 13% 254K 36s
1050K .......... .......... .......... .......... .......... 13% 252K 36s
1100K .......... .......... .......... .......... .......... 14% 301K 35s
1150K .......... .......... .......... .......... .......... 15% 156K 35s
1200K .......... .......... .......... .......... .......... 15% 183K 35s
1250K .......... .......... .......... .......... .......... 16% 197K 35s
1300K .......... .......... .......... .......... .......... 16% 169K 34s
1350K .......... .......... .......... .......... .......... 17% 127K 35s
1400K .......... .......... .......... .......... .......... 18% 166K 35s
This was saved in the text file... As... it seems like it keeps on adding new line after each change. All i need is to read the file from the bottom. And, read it every-time a change is detected.
Really helpful - Thanks for your time and efforts.
Any additional advice you wanna give me... for detecting the changes precisely. Or any exe / batch function (I call them plugins.. but..) that can help me
Once again... thanks aGerman
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 13 Sep 2017 09:51
by aGerman
Kvc wrote:it seems like it keeps on adding new line after each change.
Yes it
seems like. But I don't think so because it would be surprising if you would see all these lines in the cmd window whithout the redirection. Exactly that was the reason why I asked you to ZIP the file and upload it. Your pasted text is useless in this case because the real end-of-line characters are changed by the forum software.
Steffen
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 14 Sep 2017 10:32
by Kvc
aGerman wrote:Your pasted text is useless in this case because the real end-of-line characters are changed by the forum software.
Opps! I didn't considered that... Here's the file!
Edit 1:
I don't know what extention it wants... but can't upload bat, txt, or any other format... trying zip!
Edit 2:
Yeah! finally learned that..
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 14 Sep 2017 12:05
by pieh-ejdsch
Hello,
only times interesting What do you have to do with the file?
Do you want to display the output itself in another input prompt or calculate something else (during the download)?
Phil
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 14 Sep 2017 14:21
by aGerman
Surprisingly the end of lines are indeed CR and LF.
To write and read in parallel you have to run wget asynchronously.
Give this a go:
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set "outfile=Output.txt"
REM create backspace and carriage return characters
for /f "tokens=1,3" %%a in ('prompt $H$S^&for /f %%b in ^('copy /z "%~f0" nul'^) do %%b 2^>nul') do (set "bs=%%a"&set "cr=%%b")
REM run wget asynchronously
start /b cmd /c "2>"!outfile!" wget "YourURL""
set "line=" &set "before="
REM polling loop
:loop
REM wait a few milliseconds to reduce CPU load
>nul pathping 127.0.0.1 -n -q 1 -p 50
REM read all lines that contain a digit followed by a percent sign, the last line keeps being saved in variable line
for /f "delims=" %%i in ('2^>nul findstr /rc:"[0-9]%% " "!outfile!"') do set "line=%%i"
REM if a new line was read
if "!line!" neq "!before!" (
REM jump the cursor back to the begin of the line and overwrite the former values
<nul set /p "=!bs!!cr!!line:~0,7! !line:~62,4! !line:~67,5! !line:~73! "
REM save the line for the next comparison
set "before=!line!"
)
REM jump back to :loop as long as the download wasn't at 100%
if "!line:~62,4!" neq "100%%" goto loop
REM write line end
echo(
pause
Note that you'll end up in an infinite loop if "100%" was never read.
Steffen
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 15 Sep 2017 07:16
by Kvc
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 15 Sep 2017 07:54
by aGerman
Kvc wrote:And, One more thing... can you tell me - how to remove that annoying text line on the first line of console...
I left comments for nearly every line I wrote so it should have been clear what happens here ...
Code: Select all
REM jump the cursor back to the begin of the line and overwrite the former values
<nul set /p "=!bs!!cr!!line:~0,7! !line:~62,4! !line:~67,5! !line:~73! "
... and also as soon as you remove this line you don't need the backspace and carriage return characters anymore.
Steffen
Re: Saving a changing output to a text file... and update the file each time output changes!
Posted: 15 Sep 2017 09:45
by Kvc