lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Oct 28, 2013 at 2:20 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 28.10.2013 18:05 schröbte Rena:


#!/usr/bin/env lua5.1
local posix = require('posix')
local function spawn(program, ...)
     local read, write = posix.pipe()
     local cpid = posix.fork()
     if cpid == 0 then --child
           assert(posix.dup2(write, 1)) -- replace stdout with pipe-end

         assert(posix.execp(program, ...))
     else return {read=read, write=write, pid=cpid}
     end
end

local proc = assert(spawn('ping', '127.0.0.1'))
while true do
     local data = "" 1024))
     print("ping says:", data)
end

but ping doesn't write to the pipe, and just outputs to my terminal instead.


HTH,
Philipp




Thanks, that does help.

--
Sent from my Game Boy.