提交 2b4519ce 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

windows stdout redirect is still under develop

上级 a70421f6
#include "specwidget.h"
#include "specwidget.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
......
......@@ -23,10 +23,6 @@
<property name="text">
<string>Start</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/icons/signal.svg</normaloff>:/icons/icons/signal.svg</iconset>
</property>
</widget>
</item>
<item>
......@@ -225,8 +221,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>450</height>
<width>320</width>
<height>478</height>
</rect>
</property>
<attribute name="label">
......@@ -370,8 +366,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>165</height>
<width>320</width>
<height>478</height>
</rect>
</property>
<attribute name="label">
......@@ -534,8 +530,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>450</height>
<width>320</width>
<height>478</height>
</rect>
</property>
<attribute name="label">
......@@ -562,8 +558,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>450</height>
<width>320</width>
<height>478</height>
</rect>
</property>
<attribute name="label">
......
#include "stdout_watcher.h"
#include "stdout_watcher.h"
#include <stdio.h>
#include <thread>
#ifdef __GNUC__
......@@ -7,6 +7,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#endif
#ifdef _MSVC_LANG
#include <io.h>
#include <fcntl.h>
#endif
stdout_watcher::stdout_watcher(QObject *parent) : QThread(parent),
m_bStop(false)
{
......@@ -15,8 +20,63 @@ stdout_watcher::stdout_watcher(QObject *parent) : QThread(parent),
void stdout_watcher::stop_and_wait()
{
m_bStop = true;
fprintf (stdout,"Bye!\n");
fprintf (stderr,"Bye!\n");
wait();
}
#ifdef _MSVC_LANG
void stdout_watcher::run()
{
return;
auto pt = [&](FILE * stda,bool stderrb)->void{
HANDLE hOutputReadTmp = 0;
HANDLE hOutputWrite = 0;
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,0,0))
emit evt_stdata("[stdout watcher]:CreatePipe Error.",stderrb);
int hCrt =_open_osfhandle( (long)hOutputWrite, _O_TEXT );
FILE *hf = _fdopen( hCrt, "w" );
*stda = *hf;
int i = setvbuf( stda, NULL, _IONBF, 0 );
CHAR lpBuffer[1024];
DWORD nBytesRead;
while(!m_bStop)
{
if (!ReadFile(hOutputReadTmp, lpBuffer,sizeof(lpBuffer),
&nBytesRead,NULL) || !nBytesRead)
{
if (GetLastError() == ERROR_BROKEN_PIPE)
break; // pipe done - normal exit path.
else
emit evt_stdata("ReadFile",stderrb);
}
if (nBytesRead >0 )
{
emit evt_stdata(QByteArray(lpBuffer,nBytesRead),stderrb);
}
}
fclose(hf);
_close(hCrt);
CloseHandle(hOutputReadTmp);
CloseHandle(hOutputWrite);
};
std::thread t1(pt, stderr,true);
std::thread t2(pt, stdout,false);
t1.join();
t2.join();
}
#endif
#ifdef __GNUC__
void stdout_watcher::run()
......
#ifndef STDOUT_WATCHER_H
#ifndef STDOUT_WATCHER_H
#define STDOUT_WATCHER_H
#include <QThread>
#include <atomic>
#ifdef _MSVC_LANG
#include<windows.h>
#endif
class stdout_watcher : public QThread
{
Q_OBJECT
......@@ -14,6 +17,7 @@ signals:
void evt_stdata(QByteArray,bool stderrb);
public:
std::atomic<bool> m_bStop;
};
#endif // STDOUT_WATCHER_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册