#pike __REAL_VERSION__ |
|
|
constant contenttypes = ({ }); |
|
|
.Output filter(Standards.URI uri, string|Stdio.File data, |
string content_type, mixed ... more); |
|
|
string my_popen(array(string) args, string|void cwd, int|void wait_for_exit, |
array(string)|void watchdog_args) |
|
{ |
Stdio.File pipe0 = Stdio.File(); |
Stdio.File pipe1 = pipe0->pipe(Stdio.PROP_IPC); |
if(!pipe1) |
if(!pipe1) error("my_popen failed (couldn't create pipe).\n"); |
mapping setup = ([ "env":getenv(), "stdout":pipe1, "nice": 20 ]); |
if (cwd) |
setup["cwd"] = cwd; |
Process.create_process proc = Process.create_process(args, setup); |
pipe1->close(); |
|
|
Process.Process watchdog; |
if (wait_for_exit && watchdog_args) { |
|
array(string) wd_args = |
replace(watchdog_args + ({ }), "%p", (string) proc->pid()); |
watchdog = Process.spawn_pike(wd_args); |
} |
|
string result = pipe0->read(); |
if(!result) |
error("my_popen failed with error "+pipe0->errno()+".\n"); |
pipe0->close(); |
if (wait_for_exit) |
proc->wait(); |
|
if (watchdog) |
watchdog->kill(9); |
|
return result; |
} |
|
|