1() = evalfile ("./common.sl"); 2 3require ("process"); 4 5private define pre_exec_hook (fdlist, optarg) 6{ 7 putenv ("TEST_OPTARG=$optarg"); 8} 9 10private define test_process () 11{ 12 % This is a silly example. echo write to fd=12, which has stdout 13 % dup'd to it. wc reads from echo via fd=16, which has stdin dup'd 14 % to it. 15 variable echo = new_process (["echo", "foo bar"]; write=12, dup1=12, 16 pre_exec_hook=&pre_exec_hook, 17 pre_exec_hook_optarg="FOOBAR"); 18 19 variable wc = new_process ("wc"; write=10, dup1=10, fd16=echo.fd12, dup0=16); 20 21 variable line; 22 if (-1 == fgets (&line, wc.fp10)) 23 failed ("Failed to read from wc process: " + errno_string ()); 24 line = strcompress (line, " \t\n"); 25 if (line != "1 2 8") 26 { 27 failed ("Expected 1 2 8, got %s\n", line); 28 } 29 variable status = echo.wait (); 30 if (status == NULL) 31 failed ("wait method failed for echo"); 32 status = wc.wait (); 33 if (status == NULL) 34 failed ("wait method failed for echo"); 35} 36 37define slsh_main () 38{ 39 start_test ("process"); 40 test_process (); 41 end_test (); 42} 43