#include "shell.hpp" void shell::c_run (std::string args) { // sanity checks if ( args == "" ) { carp ("format: run [args] ..."); return; } std::string command = args; bool bg = false; // check if we run in backround if ( command.rfind ("&") + 1 == command.length () ) { bg = true; command.erase (command.length () - 2); } // create io streams for job io saga::job::ostream in; saga::job::istream out; saga::job::istream err; // run job. // Use 'host_' as target host. // use 'js_' as saga::job_service saga::job::job job; // FIXME: run job! // get job state saga::job::state state = saga::job::Unknown; // FIXME: get state // check if that worked if ( state != saga::job::Running && state != saga::job::Done ) { carp ("run failed: " + command); } if ( bg ) { // store background jobs in process table int pid = jobs_.add (job.get_job_id (), command, job); // output std::cout << "[" << pid << "] " << command << std::endl; } else { // a forground job is pulled for its stdout while ( true ) { char buffer[255]; out.read (buffer, sizeof (buffer)); if ( out.gcount () > 0 ) { std::cout << std::string (buffer, out.gcount ()); } if ( out.fail () ) { break; } } std::cout << std::endl << std::flush; } return; }