#include <cstdlib>
-#include <unistd.h>
-#include <sys/wait.h>
#include <msp/fs/dir.h>
#include <msp/io/console.h>
#include <msp/io/file.h>
string ExternalTask::get_command() const
{
string cmd;
- for(vector<string>::const_iterator i=argv.begin(); i!=argv.end(); ++i)
+ for(const string &a: argv)
{
- if(i!=argv.begin())
+ if(!cmd.empty())
cmd += ' ';
- for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+ for(char c: a)
{
- if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&')
+ if(c=='"' || c=='\'' || c==' ' || c=='\\' || c=='&')
cmd += '\\';
- cmd += *j;
+ cmd += c;
}
}
if(stdin_action==IGNORE || stdout_action==IGNORE || stderr_action==IGNORE)
{
+#ifdef _WIN32
+ devnull = new IO::File("nul", IO::M_RDWR);
+#else
devnull = new IO::File("/dev/null", IO::M_RDWR);
+#endif
if(stdin_action==IGNORE)
process->redirect_cin(*devnull);
if(stdout_action==IGNORE)
Task::Status ExternalTask::do_wait(bool block)
{
- if(process)
+ while(process)
{
- if(process->wait(block))
+ if(process->wait(block && !capture_pipe))
{
exit_code = process->get_exit_code();
delete process;
}
// Do this after waiting to avoid a race condition
- while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, Time::zero))
+ while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, 10*Time::msec))
{
char buf[1024];
unsigned len = capture_pipe->read(buf, sizeof(buf));
}
if(process)
- return RUNNING;
+ {
+ if(!block)
+ return RUNNING;
+ }
else
signal_finished.emit(!exit_code);
}