In the last episode (May 05), Martin Nilsson (rfsfiskal) @ Pike (-) developers forum said:
I just checked in Dans patch for a new popen that returns a file object instead of a string under the name fpopen. Would you rather see that popen is incompatibly replaced? If not, make up a better name than fpopen.
Apparently the lyskom gateway suddenly woke up and this entire thread arrived in my mailbox at once :)
I thought of a way to make it backwards-compatible: If you call popen("command") with no 2nd argument, default to "r", do the read() internally, and return the string.
object(Stdio.FILE)|string popen(string s, string|void mode) { int compat = 0; if (!mode) { mode = "r"; compat = 1; } object f = Stdio.FILE(); if (!f) error("Popen failed. (couldn't create file)\n");
object p = f->pipe(); if(!p) error("Popen failed. (couldn't create pipe)\n");
if (mode == "w") Process.spawn(s, p, 0, 0, destruct, f); else Process.spawn(s, 0, p, 0, destruct, f); p->close(); destruct(p);
if(compat) return f->read(); else return f; }