diff options
author | 2016-02-21 11:48:45 +0100 | |
---|---|---|
committer | 2016-02-21 11:48:45 +0100 | |
commit | cc24a339d8c0517259084b5c178d784626ba965c (patch) | |
tree | 9868e9687b5802ae0a3733712a3bbeb3bc75c953 /3rdparty/luv/examples/uvbook/uvtee.lua | |
parent | b5daabda5495dea5c50e17961ecfed2ea8619d76 (diff) |
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Second attempt
Diffstat (limited to '3rdparty/luv/examples/uvbook/uvtee.lua')
-rw-r--r-- | 3rdparty/luv/examples/uvbook/uvtee.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/3rdparty/luv/examples/uvbook/uvtee.lua b/3rdparty/luv/examples/uvbook/uvtee.lua new file mode 100644 index 00000000000..c91b066ae21 --- /dev/null +++ b/3rdparty/luv/examples/uvbook/uvtee.lua @@ -0,0 +1,35 @@ +local uv = require('luv') + +if not arg[1] then + print(string.format("please run %s filename",arg[0])) + return +end + + +local stdin = uv.new_tty(0, true) +local stdout = uv.new_tty(1, true) +--local stdin_pipe = uv.new_pipe(false) +--uv.pipe_open(stdin_pipe,0) + +local fname = arg[1] + +uv.fs_open(fname, 'w+', tonumber('644', 8), function(err,fd) + if err then + print("error opening file:"..err) + else + local fpipe = uv.new_pipe(false) + uv.pipe_open(fpipe, fd) + + uv.read_start(stdin, function(err,chunk) + if err then + print('Read error: '..err) + else + uv.write(stdout,chunk) + uv.write(fpipe,chunk) + end + end); + end +end) + +uv.run('default') +uv.loop_close() |