L
Lawrence Oluyede
What I'm trying to do is to pass some data
to a child process that execute an external process
and get back data from this external process.
---
PATH = "/usr/bin/highlight"
ARGS = "-f -l -t 8 -S %s"
LANG = "rb"
rd, wr = IO.pipe
if fork
# parent
rd.close
$stdout.reopen(wr)
wr.close
fd = File.open("/usr/lib/ruby/1.8/thread.rb")
str = fd.read
$stdout.write str
else
# child
wr.close
$stdin.reopen(rd)
rd.close
params = ARGS % LANG
cmd = "%s %s" % [PATH, params]
exec cmd
end
to a child process that execute an external process
and get back data from this external process.
---
PATH = "/usr/bin/highlight"
ARGS = "-f -l -t 8 -S %s"
LANG = "rb"
rd, wr = IO.pipe
if fork
# parent
rd.close
$stdout.reopen(wr)
wr.close
fd = File.open("/usr/lib/ruby/1.8/thread.rb")
str = fd.read
$stdout.write str
else
# child
wr.close
$stdin.reopen(rd)
rd.close
params = ARGS % LANG
cmd = "%s %s" % [PATH, params]
exec cmd
end