pike.git / lib / modules / Process.pmod

version» Context lines:

pike.git/lib/modules/Process.pmod:147:   //! Either a command line array, as the command_args   //! argument to @[create_process()], or a string that   //! will be splitted into a command line array by   //! calling @[split_quoted_string()] in an operating   //! system dependant mode.   //! @param modifiers   //! It takes all the modifiers @[Process.Process] accepts, with   //! the exception of stdout and stderr. Since the point of this   //! function is to handle those you can not supply your own.   //! - //! If modifiers->stdin is set to a string it will automaticly be + //! If @expr{modifiers->stdin@} is set to a string it will automaticly be   //! converted to a pipe that is fed to stdin of the started process.   //!   //! @seealso   //! @[Process.Process] @[create_process]   //!   //! @returns   //! @mapping   //! @member string "stdout"   //! Everything the process wrote on stdout.   //! @member string "stderr"
pike.git/lib/modules/Process.pmod:188:       if(!modifiers)    modifiers = ([]);       if(modifiers->stdout || modifiers->stderr)    throw( ({ "Can not redirect stdout or stderr in run_process, "    "please use Process.Process instead.", backtrace() }) );       Stdio.File mystdout = Stdio.File();    Stdio.File mystderr = Stdio.File(); +  Stdio.File mystdin;       object p; -  if(modifiers->stdin && stringp(modifiers->stdin)) +  if(stringp(modifiers->stdin))    { -  Stdio.File mystdin = Stdio.File(); +  mystdin = Stdio.File();    stdin_str = modifiers->stdin;    p = Process(cmd, modifiers + ([    "stdout":mystdout->pipe(),    "stderr":mystderr->pipe(),    "stdin":mystdin->pipe(Stdio.PROP_IPC|Stdio.PROP_REVERSE)    ])); -  Shuffler.Shuffle sf = Shuffler.Shuffler()->shuffle( mystdin ); -  sf->add_source(stdin_str); -  sf->start(); +     }    else    p = Process(cmd, modifiers + ([    "stdout":mystdout->pipe(),    "stderr":mystderr->pipe(),    ]));      #if constant(Thread.Thread) -  array readthreads = ({ +  array threads = ({    thread_create( lambda() { gotstdout = mystdout->read(); } ),    thread_create( lambda() { gotstderr = mystderr->read(); } )    });    -  +  if (mystdin) { +  threads += ({ +  thread_create(lambda() { mystdin->write(stdin_str); } ) +  }); +  }    -  if(stdin_str) -  while( !p->status() || p->status() == 1 ) -  Pike.DefaultBackend( 1.0 ); +     exitcode = p->wait(); -  readthreads->wait(); +  threads->wait();   #else //No threads, use callbacks    mystdout->set_read_callback( lambda( mixed i, string data) {    gotstdout += data;    } );    mystderr->set_read_callback( lambda( mixed i, string data) {    gotstderr += data;    } );    -  +  if (mystdin) { +  Shuffler.Shuffle sf = Shuffler.Shuffler()->shuffle( mystdin ); +  sf->add_source(stdin_str); +  sf->start(); +  } +     while( !p->status() || p->status() == 1 )    Pike.DefaultBackend( 1.0 );       mystdout->set_read_callback(0);    mystderr->set_read_callback(0);       gotstdout += mystdout->read();    gotstderr += mystderr->read();       exitcode = p->wait();