문제

I know I can use the FOR /F to get the command process output, as follows:

FOR /F %%I IN ('myprogram.cmd') DO (
  do something with %%I
)

However, above method I have to wait until "myprogram.cmd" is finished then get the entire output. I want to get the output in real time when "myprogram.cmd" is running.

Is it possible to use windows script only?

도움이 되었습니까?

해결책

Windows programs most certainly can process the output of another process asynchronously using pipes. Scripting languages like VBScript, JScript, and PowerShell should be able to do this easily. You simply pipe your output into your script, and the script reads from stdin within a loop, terminating when end of file is reached.

But doing so using pure batch is quite difficult and has significant limitations. It requires multiple batch processes, and a temporary file. The first batch process uses FIND to read from stdin and redirects the output to the temp file. The second batch process reads from the temp file using SET /P. See my batchTee.bat for an example of how this could be done.

But I don't recommend doing this except as an academic excercise. Instead you should use one of the other scripting languages that can do this easily.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top