Hey im looking for a way to make a batch file read a constantly updating text file and write the output to the console is there anyway to do so?
Can you post what did you tried as code until now and explain more your aim ?
What did you mean by reading a file? from what this comes up ? this file is generated by a command line or by a program or what else ?Windows Batch File Example: Read Text File
The below batch program will read the text file (dummy.txt) from the current directory and will put the line into a variable, then will echo (print) the line on the screen.
Contents of the dummy.txt file :
This is the first line. This is the second line. This is the third line. This is the forth line. This is the fifth line.readfile.bat
@echo off for /f "tokens=*" %%s in (dummy.txt) do ( echo %%s ) pauseEdit : Monitor A Text File From Windows PowerShell In Real Time
You can give a try with this batch file that use powershell and modify it with your Input file path :
@echo off Title Monitor Log or Text File Changes in Real Time Set "InputFile=%windir%\system32\drivers\etc\hosts" Set /a "xx_number_of_lines_at_the_end=10" Powershell -C "Get-content %InputFile% -Tail %xx_number_of_lines_at_the_end% -Wait"further reading about 5 Ways To Monitor Log or Text File Changes in Real Time
message edited by Hackoo
I doubt if batch can do this. Mebbe vbscript can. Call it "feed.vbs" or whatever, but
that's what used for example. save the file, then: 'feed.vbs file_name]''begin vbscript Feed.vbs: keep reading a file and putting to stdout set fso=createobject("scripting.filesystemobject") on error resume next set u=fso.opentextfile(wscript.arguments(0),1) if err.number > 0 then wscript.echo err.number&" "&err.description wscript.quit end if do do until u.atendofstream p=u.read(1) if len(p) > 0 then wscript.stdout.write p loop loop 'end vbscript "feed.vbs"
As it stands, the target, or feed file needs to pre-exist, but no minimum size. Worked in my tests. BUT, some apps, services, or web sites might secure output until production is closed.message edited by nbrane
Here is another example to Monitor Text File Changes in Real Time by downloading RSS Feed and read it with Powershell and Batch : @echo off Title Monitor Text File Changes in Real Time by downloading RSS Feed and read it with Powershell and Batch Set "URL=http://www.tmz.com/rss.xml" Set /a "Update_In_Seconds=20" Set "InputFile=%~dp0TMZ_feed.txt" Set psCmd="&{$feed=[xml](new-object system.net.webclient).downloadstring('%URL%');$feed.rss.channel.item | format-table title,link | Out-String -Width 1000 | Out-File "%InputFile%"}" ::---------------------------------------------------------------------- :Main Call :RunPS %psCmd% RSS Call :ReadFile "%InputFile%" Timeout /T %Update_In_Seconds% /NoBreak>NUL Goto Main Exit ::---------------------------------------------------------------------- :ReadFile <InputFile> cls @for /f "tokens=*" %%s in ('Type "%~1"') do ( echo %%s ) Exit /B ::---------------------------------------------------------------------- :RunPS <PassPSCMD> <RetValue> for /F "usebackq tokens=*" %%i in (`Powershell %1`) do set "%2=%%i" Goto:eof :: End of :RunPS function ::----------------------------------------------------------------------message edited by Hackoo
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |