void ButtonLaunch::TextOutput() { // Prevent this from being called twice. disconnect(m_pProcess, SIGNAL(readyRead()), this, SLOT(TextOutput())); // Create a subwindow to display stdout text from the app. m_pTextWindow = new QTextEdit(this); m_pTextWindow->setStyleSheet("QScrollBar{min-width: 30; min-height: 30}"); m_pTextWindow->setFontPointSize(16); // Display the text window the same size as the main menu. m_pSubWindow = m_pMdiArea->addSubWindow(m_pTextWindow); m_pSubWindow->resize(m_pMdiArea->size()); m_pSubWindow->setWindowFlags(Qt::FramelessWindowHint); m_pSubWindow->show(); m_pSubWindow->setFocus(); // Hook signals to handle additional text output and process closing. connect(m_pProcess, SIGNAL(readyRead()), this, SLOT(ReadOutput())); connect(m_pProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(Finished())); //qDebug() << "TextOutput"; ReadOutput(); }
//============================================================================ // NTask::Execute : Execute the task. //---------------------------------------------------------------------------- NString NTask::Execute(NTime waitFor) { NString theResult; NTime endTime; NStatus theErr; // Get the state we need endTime = NTimeUtilities::GetTime() + waitFor; // Execute the command theErr = Launch(); NN_ASSERT_NOERR(theErr); // Wait for the results while (IsRunning()) { if (waitFor >= kNTimeNone && NTimeUtilities::GetTime() >= endTime) break; UpdateTask(kTaskSleep); } theResult = ReadOutput() + ReadError(); return(theResult); }
void ButtonLaunch::Finished() { ReadOutput(); // Calculate the position for the Close button in the bottom right corner. const QPoint position(m_pTextWindow->size().width() - 140, m_pTextWindow->size().height() - 80); // Create the close button with a text label. m_pCloseButton = new QPushButton("&Close", m_pTextWindow); m_pCloseButton->setMinimumSize(QSize(64, 64)); m_pCloseButton->move(position); m_pCloseButton->show(); // Connect button events to close this object. connect(m_pCloseButton, SIGNAL(clicked(bool)), this, SLOT(Close())); //qDebug() << "Finished"; }
int main() { cout<<"Equalizer"<<endl; BSPara BS; BS.initBSPara(); UserPara User(&BS); Equalizer Eq(&BS,&User); FIFO<complex<float> > EqIn(1,Eq.InBufSz); FIFO<complex<float> > EqOut(1,Eq.OutBufSz); //ReadInputFromFiles(&EqIn,(Eq.InBufSz),"LSCELSEqInputReal","LSCELSEqInputImag"); //GeneRandomInput(&EqIn,Eq.InBufSz,"LSCELSEqRandomInputReal","LSCELSEqRandomInputImag"); GeneRandomInput(&EqIn,Eq.InBufSz); Eq.Equalizing(&EqIn,&EqOut); //WriteOutputToFiles(&EqOut,(Eq.OutBufSz),"LSCELSEqOutputReal","LSCELSEqOutputImag"); //WriteOutputToFiles(&EqOut,(Eq.OutBufSz),"LSCELSEqRandomOutputReal","LSCELSEqRandomOutputImag"); ReadOutput(&EqOut,(Eq.OutBufSz)); }
int RunInProcCompiler( _In_ const wstring& processPath, _In_ const list<wstring> args, _Out_ vector<BYTE>& stdOut, _Out_ vector<BYTE>& stdErr) { SECURITY_ATTRIBUTES attr; attr.nLength = sizeof(SECURITY_ATTRIBUTES); attr.bInheritHandle = TRUE; attr.lpSecurityDescriptor = NULL; // Get stdin to pass to csc.exe auto stdIn = GetStdHandle(STD_INPUT_HANDLE); // Create handles for the child to write to and the parent to read from HANDLE stdOutRead; HANDLE stdOutWrite; HANDLE stdErrRead; HANDLE stdErrWrite; HANDLE inDup; auto thisHandle = GetCurrentProcess(); DuplicateHandle( thisHandle, stdIn, thisHandle, &inDup, 0, TRUE, DUPLICATE_SAME_ACCESS); if (!CreatePipe(&stdOutRead, &stdOutWrite, &attr, 0)) { FailWithGetLastError(GetResourceString(IDS_ConnectToInProcCompilerFailed)); } if (!CreatePipe(&stdErrRead, &stdErrWrite, &attr, 0)) { FailWithGetLastError(GetResourceString(IDS_ConnectToInProcCompilerFailed)); } // Mark the read end of the pipes non-inheritable if (!SetHandleInformation(stdOutRead, HANDLE_FLAG_INHERIT, 0)) { FailWithGetLastError(GetResourceString(IDS_ConnectToInProcCompilerFailed)); } if (!SetHandleInformation(stdErrRead, HANDLE_FLAG_INHERIT, 0)) { FailWithGetLastError(GetResourceString(IDS_ConnectToInProcCompilerFailed)); } PROCESS_INFORMATION procInfo = {}; STARTUPINFO startInfo = {}; BOOL success = FALSE; startInfo.cb = sizeof(STARTUPINFO); startInfo.hStdOutput = stdOutWrite; startInfo.hStdInput = inDup; startInfo.hStdError = stdErrWrite; startInfo.dwFlags |= STARTF_USESTDHANDLES; // Assemble the command line wstringstream argsBuf; // Quote the exe path in case there are spaces argsBuf << '"'; argsBuf << processPath; argsBuf << '"'; // Space seperate every argument for (auto arg : args) { argsBuf << ' '; argsBuf << arg; } auto argsString = argsBuf.str(); auto argsCpy = make_unique<wchar_t[]>(argsString.size() + 1); wcscpy_s(argsCpy.get(), argsString.size() + 1, argsString.c_str()); // Create the child process. success = CreateProcess(NULL, argsCpy.get(), // command line NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, NULL, // use parent's environment NULL, // use parent's current directory &startInfo, // STARTUPINFO pointer &procInfo); // receives PROCESS_INFORMATION CloseHandle(stdOutWrite); CloseHandle(inDup); CloseHandle(stdErrWrite); if (success) { // Read stdout and stderr from the process ReadOutput(stdOutRead, stdOut); ReadOutput(stdErrRead, stdErr); // Wait for the process to exit and return the exit code LogFormatted(IDS_CreatedProcess, procInfo.dwProcessId); WaitForSingleObject(procInfo.hProcess, INFINITE); DWORD exitCode = -1; GetExitCodeProcess(procInfo.hProcess, &exitCode); // Cleanup CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread); CloseHandle(stdOutRead); CloseHandle(stdErrRead); return exitCode; } else { CloseHandle(stdOutRead); CloseHandle(stdErrRead); FailWithGetLastError(GetResourceString(IDS_CreatingProcess)); // Unreachable return -1; } }
bool ReadOutput(matrix<FAR_CHAR_INFO>& Buffer, SMALL_RECT& ReadRegion) const { COORD BufferCoord = {}; return ReadOutput(Buffer, BufferCoord, ReadRegion); }