1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
#pike __REAL_VERSION__ 
 
//! @decl constant array(string) contenttypes 
//! The MIME content types this object can filter. 
constant contenttypes = ({ }); 
 
//! @decl optional constant array(string) fields 
//! The different fields this object can extract from the media. The 
//! list can contain any of the following values. 
//! @string 
//!   @value "body" 
//!   @value "title" 
//!   @value "keywords" 
//!   @value "description" 
//!   @value "robots" 
//!   @value "headline" 
//!   @value "modified" 
//!   @value "author" 
//!   @value "summary" 
//! @endstring 
optional constant fields = ({}); 
 
//! 
.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) 
  // A smarter version of Process.popen: No need to quote arguments. 
{ 
  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(); 
 
  //  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); 
  } 
 
  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; 
}