void exe_prepa(t_shell *sh, CMD *c, int pip_out[2], int pip_error[2]) { close(pip_out[0]); close(pip_error[0]); execute_shell(sh, c, pip_out[1], pip_error[1]); close(pip_out[1]); close(pip_error[1]); }
string pipe_link_rep::start () { #ifndef OS_MINGW if (alive) return "busy"; if (DEBUG_AUTO) debug_io << "Launching '" << cmd << "'\n"; int e1= pipe (pp_in ); (void) e1; int e2= pipe (pp_out); (void) e2; int e3= pipe (pp_err); (void) e3; pid= fork (); if (pid==0) { // the child setsid(); close (pp_in [OUT]); close (pp_out [IN ]); close (pp_err [IN ]); dup2 (pp_in [IN ], STDIN ); close (pp_in [IN ]); dup2 (pp_out [OUT], STDOUT); close (pp_out [OUT]); dup2 (pp_err [OUT], STDERR); close (pp_err [OUT]); execute_shell (cmd); exit (127); // exit (system (cmd) != 0); } else { // the main process in = pp_in [OUT]; close (pp_in [IN]); out= pp_out [IN ]; close (pp_out [OUT]); err= pp_err [IN ]; close (pp_err [OUT]); alive= true; snout = socket_notifier (out, &pipe_callback, this, NULL); snerr = socket_notifier (err, &pipe_callback, this, NULL); add_notifier (snout); add_notifier (snerr); if (/* !banner */ true) return "ok"; else { int r; char outbuf[1024]; r= ::read (out, outbuf, 1024); if (r == 1 && outbuf[0] == TERMCHAR) return "ok"; alive= false; if (-1 != killpg(pid,SIGTERM)) { sleep(2); killpg(pid,SIGKILL); } wait (NULL); if (r == -1) return "Error: the application does not reply"; else return "Error: the application did not send its usual startup banner"; } } #else return "Error: pipes not implemented"; #endif }
void task<const char*>::operator()() { execute_shell(substance); }
int execute(const char* command) { return execute_shell(command); }