[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Read user input from terminal when a pipe is used
- From: Scott Fial <scott@...>
- Date: Fri, 06 Dec 2013 11:45:33 -0800
Hi Alexander,
On 12/6/2013 6:09 AM, Alexander Schulz wrote:
Hey,
i want to create a script with lua that reads from a pipe and allows to read input from the user terminal.
Example: history -n | tail -n 10 | my_script
In this case is io.stdin a file descriptor to the pipe.
How can i get now in lua a file descriptor on the current terminal?
The following should work under Linux, OS X, and Cygwin:
-- open terminal explicitly
local tty = io.open('/dev/tty', 'r')
-- read a line from stdin (the pipe)
local stdin_line = io.read()
-- read a line directly from terminal
local tty_line = tty:read()
-- close terminal when done
tty:close()
Scott