Yaroslav Rodionov
Yaroslav Rodionov

Reputation: 55

Read console output realtime in lua, take 2

I have a process process.exe which monitors some behavior and prints all the changes into console window in real time as it is running. As a standalone thing it works perfectly.

I need to read its output with lua script. I tried to use the answer provided here:

Read console output realtime in lua

local pipe = io.popen('process.exe "myPath"')
for line in pipe:lines() do
    print(line)
end
pipe:close()

The point is, this lua script produces a hanging cmd.exe window and doens't print anything into my LUA console. And only after I close this cmd window the script prints all the output. So I don't know how to solve the problem.

Upvotes: 1

Views: 577

Answers (2)

Hugh
Hugh

Reputation: 361

This is just 1 instruction you've given to the lua interpreter, so it's only going to act once when you run the script. It'll run proccess.exe, wait for it to complete, and then write the entire output to console.

If proccess.exe is recording data as it happens to a file on your computer, use a while true do statement to check the file for changes, printing anything new that arrives.

I'd be happy to write this for you if required.

Upvotes: 0

koyaanisqatsi
koyaanisqatsi

Reputation: 2793

It seems that process.exe is not ending by itself and therefore...
"And only after I close this cmd window the script prints all the output."
...means that you have to close process.exe by yourself.

If so and you need only the output then use os.execute().
Alone not in: for ... do ... end

Upvotes: 1

Related Questions