eb01b42010-10-26Martin Stjernholm #pike __REAL_VERSION__
87e9262001-06-22Martin Nilsson 
e1d7152000-11-24Johan Schön //! The MIME content types this class can filter.
df57a22001-01-02Johan Schön constant contenttypes = ({ });
e1d7152000-11-24Johan Schön 
28d6b82001-08-08Martin Nilsson //!
40a44d2004-08-07Johan Schön .Output filter(Standards.URI uri, string|Stdio.File data,
e262e52001-06-05Per Hedbor  string content_type, mixed ... more);
32e8b52001-06-28Johan Schön 
5b2f182011-01-26Jonas Wallden  string my_popen(array(string) args, string|void cwd, int|void wait_for_exit, array(string)|void watchdog_args)
94b6102001-08-08Fredrik Noring  // A smarter version of Process.popen: No need to quote arguments.
3524712015-05-26Martin Nilsson {
94b6102001-08-08Fredrik Noring  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");
8b420e2005-05-23Anders Johansson  mapping setup = ([ "env":getenv(), "stdout":pipe1, "nice": 20 ]);
b225322003-01-20Jonas Wallden  if (cwd) setup["cwd"] = cwd;
47fcc42003-03-19Jonas Wallden  Process.create_process proc = Process.create_process(args, setup);
94b6102001-08-08Fredrik Noring  pipe1->close();
5b2f182011-01-26Jonas Wallden  // Launch watchdog if provided (requires wait_for_exit) Process.Process watchdog; if (wait_for_exit && watchdog_args) { // Insert pid of running process where caller used "%p" array(string) wd_args = replace(watchdog_args + ({ }), "%p", (string) proc->pid()); watchdog = Process.spawn_pike(wd_args); }
3524712015-05-26Martin Nilsson 
94b6102001-08-08Fredrik Noring  string result = pipe0->read(); if(!result) error("my_popen failed with error "+pipe0->errno()+".\n"); pipe0->close();
47fcc42003-03-19Jonas Wallden  if (wait_for_exit) proc->wait();
3524712015-05-26Martin Nilsson 
5b2f182011-01-26Jonas Wallden  if (watchdog) watchdog->kill(9);
3524712015-05-26Martin Nilsson 
94b6102001-08-08Fredrik Noring  return result;
32e8b52001-06-28Johan Schön }