fix clang format and clear flag for read process out\err
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ _unsused
|
|||||||
CMakeLists.txt.user*
|
CMakeLists.txt.user*
|
||||||
/include
|
/include
|
||||||
/release
|
/release
|
||||||
|
/build*
|
||||||
|
|||||||
@@ -171,10 +171,7 @@ void PIProcess::startProc(bool detached) {
|
|||||||
if (g_in) PRIVATE->tf_in = freopen(f_in.path().data(), "r", stdin);
|
if (g_in) PRIVATE->tf_in = freopen(f_in.path().data(), "r", stdin);
|
||||||
if (g_out) PRIVATE->tf_out = freopen(f_out.path().data(), "w", stdout);
|
if (g_out) PRIVATE->tf_out = freopen(f_out.path().data(), "w", stdout);
|
||||||
if (g_err) PRIVATE->tf_err = freopen(f_err.path().data(), "w", stderr);
|
if (g_err) PRIVATE->tf_err = freopen(f_err.path().data(), "w", stderr);
|
||||||
# ifndef WINDOWS
|
|
||||||
if (!wd.isEmpty())
|
|
||||||
if (!chdir(wd.data())) piCoutObj << "Error while set working directory";
|
|
||||||
# endif
|
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
GetStartupInfoA(&(PRIVATE->si));
|
GetStartupInfoA(&(PRIVATE->si));
|
||||||
piZeroMemory(PRIVATE->pi);
|
piZeroMemory(PRIVATE->pi);
|
||||||
@@ -196,15 +193,19 @@ void PIProcess::startProc(bool detached) {
|
|||||||
}
|
}
|
||||||
CloseHandle(PRIVATE->pi.hThread);
|
CloseHandle(PRIVATE->pi.hThread);
|
||||||
CloseHandle(PRIVATE->pi.hProcess);
|
CloseHandle(PRIVATE->pi.hProcess);
|
||||||
} else
|
} else {
|
||||||
piCoutObj << "\"CreateProcess\" error: %1"_tr("PIProcess").arg(errorString());
|
piCoutObj << "\"CreateProcess\" error: %1"_tr("PIProcess").arg(errorString());
|
||||||
# else
|
}
|
||||||
|
# endif
|
||||||
|
# ifndef WINDOWS
|
||||||
|
if (!wd.isEmpty()) {
|
||||||
|
if (!chdir(wd.data())) piCoutObj << "Error while set working directory";
|
||||||
|
}
|
||||||
// cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
// cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;
|
||||||
if (execve(str.data(), (char * const *)argscc, (char * const *)envcc) < 0)
|
if (execve(str.data(), (char * const *)argscc, (char * const *)envcc) < 0) {
|
||||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
piMinSleep();
|
piMinSleep();
|
||||||
// cout << "wait" << endl;
|
// cout << "wait" << endl;
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
@@ -222,6 +223,16 @@ else {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PIByteArray PIProcess::readFile(PIFile & f, bool clear)
|
||||||
|
{
|
||||||
|
f.open(PIIODevice::ReadOnly);
|
||||||
|
const auto ret = f.readAll();
|
||||||
|
if (clear) {
|
||||||
|
f.clear();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIProcess::terminate() {
|
void PIProcess::terminate() {
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
@@ -255,6 +266,14 @@ else {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PIByteArray PIProcess::readOutput(bool clear) {
|
||||||
|
return readFile(f_out, clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
PIByteArray PIProcess::readError(bool clear) {
|
||||||
|
return readFile(f_err, clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PIProcess::currentPID() {
|
int PIProcess::currentPID() {
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
|
|||||||
@@ -99,18 +99,11 @@ public:
|
|||||||
|
|
||||||
//! \~english Returns all attached execution output stream
|
//! \~english Returns all attached execution output stream
|
||||||
//! \~russian
|
//! \~russian
|
||||||
PIByteArray readOutput() {
|
PIByteArray readOutput(bool clear = false);
|
||||||
f_out.open(PIIODevice::ReadOnly);
|
|
||||||
return f_out.readAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \~english Returns all attached execution error stream
|
//! \~english Returns all attached execution error stream
|
||||||
//! \~russian
|
//! \~russian
|
||||||
PIByteArray readError() {
|
PIByteArray readError(bool clear = false);
|
||||||
f_err.open(PIIODevice::ReadOnly);
|
|
||||||
return f_err.readAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns current attached execution environment
|
//! \~english Returns current attached execution environment
|
||||||
//! \~russian
|
//! \~russian
|
||||||
@@ -227,6 +220,7 @@ private:
|
|||||||
void run() override;
|
void run() override;
|
||||||
void exec_();
|
void exec_();
|
||||||
void startProc(bool detached);
|
void startProc(bool detached);
|
||||||
|
PIByteArray readFile(PIFile & f, bool clear);
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
PIStringList args, env;
|
PIStringList args, env;
|
||||||
|
|||||||
Reference in New Issue
Block a user