# from Ben Bleything
# on Monday 17 July 2006 06:42 pm:
>If it truly is more complex, then let's see an example or get more
>details. Obviously the code he sent was fake, but I'd like to know
> what the real problem is so we can see if there might be a way to
> avoid a dangerous shell operation.
Actually, it might not be so dangerous.
Chris: write a *good* perl script that does everything you want instead
of using -e and don't put any arguments on the command line if you can
possibly avoid it.
Unless I'm mistaken, you have to fork and read your child's output if
you need to capture anything.
---
#!/usr/bin/perl
# myscript.pl
(-t STDIN) and die "no pipe";
while(my $line = <STDIN> ) {
chomp($line);
push(@stuff, $line);
}
print join("\n", @stuff);
---
def test( items )
$stderr.puts "I'm #{Process.pid}"
IO.popen("-") do |h|
unless(h)
$stderr.puts "I'm #{Process.pid} (parent: #{Process.ppid})"
IO.popen("./myscript.pl", mode="w") do |p|
items.each do |i|
p.puts( i )
end
end
else
$stderr.puts "child said #{h.read}"
end
end
$stderr.puts "I'm #{Process.pid}"
end
test([:foo, :bar, :baz, :wibble]);
>> CPAN is your friend.
>So is rubyforge. http://geocoder.rubyforge.org/ :)
Ahh, but the old friends are just so wise. IPC::Run would have done the
above in one line and caught stderr as well as the exit code of the
child.
Isn't there an inline module for ruby yet?
--Eric
--
"...our schools have been scientifically designed to
prevent overeducation from happening."
--William Troy Harris
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby