Starting a batch file using vb and streaming output to variable in real time -


(in program i'm starting batch file this:

dim p1 new process     dim psi new processstartinfo(appdata & "file.bat") psi.redirectstandarderror = true psi.redirectstandardoutput = true psi.createnowindow = true psi.windowstyle = processwindowstyle.hidden psi.useshellexecute = false p1 = process.start(psi) 

this batch file outputs 1 or more new lines every second or so. goal read these lines in real time. want have updated data every 0.5-1 second.

p1.standardoutput.readtoend() 

the above doesn't work. every method i've tried far waits batch file finish, moment don't need info anymore. :p

there's gotta simple i'm missing, can't seem find it.)

edit: using new trick:

addhandler p1.outputdatareceived, addressof outputhandler1 addhandler p1.errordatareceived, addressof errorhandler1 miner1.beginoutputreadline()  private shared sub outputhandler1(byval sendingprocess object, byval outline datareceivedeventargs)   if not string.isnullorempty(outline.data)     msgbox(outline.data)   end if end sub 

same sub errorhandler1

this works on other processes (in real time), not on mine unfortunately :p

you don't explain program structure think should start batch program in thread , keep reading in main thread (or opposite) neither thread block.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -