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*
|
||||
/include
|
||||
/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_out) PRIVATE->tf_out = freopen(f_out.path().data(), "w", stdout);
|
||||
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
|
||||
GetStartupInfoA(&(PRIVATE->si));
|
||||
piZeroMemory(PRIVATE->pi);
|
||||
@@ -196,15 +193,19 @@ void PIProcess::startProc(bool detached) {
|
||||
}
|
||||
CloseHandle(PRIVATE->pi.hThread);
|
||||
CloseHandle(PRIVATE->pi.hProcess);
|
||||
} else
|
||||
} else {
|
||||
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;
|
||||
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();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
piMinSleep();
|
||||
// cout << "wait" << endl;
|
||||
if (!detached) {
|
||||
@@ -222,6 +223,16 @@ else {
|
||||
# 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() {
|
||||
# ifdef WINDOWS
|
||||
@@ -255,6 +266,14 @@ else {
|
||||
# endif
|
||||
}
|
||||
|
||||
PIByteArray PIProcess::readOutput(bool clear) {
|
||||
return readFile(f_out, clear);
|
||||
}
|
||||
|
||||
PIByteArray PIProcess::readError(bool clear) {
|
||||
return readFile(f_err, clear);
|
||||
}
|
||||
|
||||
|
||||
int PIProcess::currentPID() {
|
||||
# ifdef WINDOWS
|
||||
|
||||
@@ -99,18 +99,11 @@ public:
|
||||
|
||||
//! \~english Returns all attached execution output stream
|
||||
//! \~russian
|
||||
PIByteArray readOutput() {
|
||||
f_out.open(PIIODevice::ReadOnly);
|
||||
return f_out.readAll();
|
||||
}
|
||||
PIByteArray readOutput(bool clear = false);
|
||||
|
||||
//! \~english Returns all attached execution error stream
|
||||
//! \~russian
|
||||
PIByteArray readError() {
|
||||
f_err.open(PIIODevice::ReadOnly);
|
||||
return f_err.readAll();
|
||||
}
|
||||
|
||||
PIByteArray readError(bool clear = false);
|
||||
|
||||
//! \~english Returns current attached execution environment
|
||||
//! \~russian
|
||||
@@ -227,6 +220,7 @@ private:
|
||||
void run() override;
|
||||
void exec_();
|
||||
void startProc(bool detached);
|
||||
PIByteArray readFile(PIFile & f, bool clear);
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
PIStringList args, env;
|
||||
|
||||
Reference in New Issue
Block a user