int Redirector::StdErrThread(HANDLE hStdErrRead) { DWORD nBytesRead; CHAR lpszBuffer[BUFFER_SIZE + 1] = {0}; while (m_bRunThread) { if (! ::ReadFile(hStdErrRead, lpszBuffer, BUFFER_SIZE, &nBytesRead, NULL) || nBytesRead == 0) { DWORD dwError = ::GetLastError(); //if (dwError == ERROR_BROKEN_PIPE)// pipe done - normal exit path. break; } if (nBytesRead > 0) { // Virtual function to notify derived class that // characters are writted to stderr. OnChildStdErrWrite(lpszBuffer); } ZeroMemory(lpszBuffer, sizeof(lpszBuffer)); } return 0; }
int QIOProcessWorker::executeProcess() { if (this->cmd.length() <= 0) return 0; this->child_process = new QProcess(this); if (this->child_process != NULL) { this->child_terminated = false; connect(this->child_process, SIGNAL(readyReadStandardOutput()), this, SLOT(OnChildStdOutWrite())); connect(this->child_process, SIGNAL(readyReadStandardError()), this, SLOT(OnChildStdErrWrite())); connect(this->child_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(OnChildTerminated(int, QProcess::ExitStatus))); connect(this->child_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(OnChildError(QProcess::ProcessError))); this->child_process->start(cmd, arguments, QIODevice::ReadWrite); while (!this->should_terminate() && !this->child_terminated) { char input; if (this->in(input, &this->child_terminated)) { if (this->child_process->isWritable() && this->child_process->state() == QProcess::Running) this->child_process->write(&input, 1); } QCoreApplication::processEvents(); } while (!this->child_terminated) { this->child_process->kill(); QCoreApplication::processEvents(); } delete this->child_process; this->child_process = NULL; QRegExp re(QString("[\\r\\n]Malbolge code written to (.*)[\\r\\n]")); int match = re.indexIn(this->child_process_stdout); if (match >= 0) { emit AssemblyOutput(re.cap(1)); } return this->child_exit_code; }else