This commit is contained in:
2025-08-13 22:29:44 +03:00
parent 39266f8c3c
commit a41379a40e

View File

@@ -9,18 +9,18 @@
Process Process
Ivan Pelipenko peri4ko@yandex.ru Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PIPROCESS_H #ifndef PIPROCESS_H
@@ -55,55 +55,63 @@ public:
int pID() const; int pID() const;
//! \~english Returns current attached execution working directory or empty string if it wasn`t set //! \~english Returns current attached execution working directory or empty string if it wasn`t set
//! \~russian //! \~russian Возвращает рабочую директорию выполнения или пустую строку, если не установлена
PIString workingDirectory() const { return wd; } PIString workingDirectory() const { return wd; }
//! \~english Set attached execution working directory //! \~english Set attached execution working directory
//! \~russian //! \~russian Устанавливает рабочую директорию для выполнения
void setWorkingDirectory(const PIString & path) { wd = path; } void setWorkingDirectory(const PIString & path) { wd = path; }
//! \~english Rseet attached execution working directory, application working dir will be used //! \~english Rseet attached execution working directory, application working dir will be used
//! \~russian //! \~russian Сбрасывает рабочую директорию, будет использоваться директория приложения
void resetWorkingDirectory() { wd.clear(); } void resetWorkingDirectory() { wd.clear(); }
//! \~english Returns all attached execution output stream //! \~english Returns all attached execution output stream
//! \~russian //! \~russian Возвращает весь вывод из стандартного потока вывода (stdout)
PIByteArray readOutput(); PIByteArray readOutput();
//! \~english Returns all attached execution error stream //! \~english Returns all attached execution error stream
//! \~russian //! \~russian Возвращает весь вывод из потока ошибок (stderr)
PIByteArray readError(); PIByteArray readError();
//! \~english Write data to attached execution input stream //! \~english Write data to attached execution input stream
//! \~russian //! \~russian Записывает данные в стандартный поток ввода (stdin)
bool writeInput(const PIByteArray & data); bool writeInput(const PIByteArray & data);
//! \~english Close attached execution input stream and send EOF //! \~english Close attached execution input stream and send EOF
//! \~russian //! \~russian Закрывает поток ввода (stdin) и отправляет EOF
void closeInput(); void closeInput();
//! \~english Enable or disable writing to process stdin
//! \~russian Включает или отключает запись в стандартный поток ввода (stdin) процесса
void enableWriteStdIn(bool on = true); void enableWriteStdIn(bool on = true);
//! \~english Enable or disable reading from process stdout
//! \~russian Включает или отключает чтение из стандартного потока вывода (stdout) процесса
void enableReadStdOut(bool on = true); void enableReadStdOut(bool on = true);
//! \~english Enable or disable reading from process stderr
//! \~russian Включает или отключает чтение из потока ошибок (stderr) процесса
void enableReadStdErr(bool on = true); void enableReadStdErr(bool on = true);
//! \~english Returns current attached execution environment //! \~english Returns current attached execution environment
//! \~russian //! \~russian Возвращает текущее окружение выполнения
PIStringList environment() { return env; } PIStringList environment() { return env; }
//! \~english Clear current attached execution environment. Call before \a exec() //! \~english Clear current attached execution environment. Call before \a exec()
//! \~russian //! \~russian Очищает окружение выполнения. Вызывать перед \a exec()
void clearEnvironment() { env.clear(); } void clearEnvironment() { env.clear(); }
//! \~english Remove variable "variable" from current attached execution environment. Call before \a exec() //! \~english Remove variable "variable" from current attached execution environment. Call before \a exec()
//! \~russian //! \~russian Удаляет переменную "variable" из окружения выполнения. Вызывать перед \a exec()
void removeEnvironmentVariable(const PIString & variable); void removeEnvironmentVariable(const PIString & variable);
//! \~english Set variable "variable" to "value" in current attached execution environment. Call before \a exec() //! \~english Set variable "variable" to "value" in current attached execution environment. Call before \a exec()
//! \~russian //! \~russian Устанавливает значение "value" для переменной "variable" в окружении выполнения. Вызывать перед \a exec()
void setEnvironmentVariable(const PIString & variable, const PIString & value); void setEnvironmentVariable(const PIString & variable, const PIString & value);
//! \~english Start attached execution "program" with one argument "arg" //! \~english Start attached execution "program" with one argument "arg"
//! \~russian //! \~russian Запускает выполнение "program" с одним аргументом "arg"
void exec(const PIString & program, const PIString & arg) { void exec(const PIString & program, const PIString & arg) {
args.clear(); args.clear();
args << program << arg; args << program << arg;
@@ -127,33 +135,37 @@ public:
EVENT1(execStarted, PIString, program); EVENT1(execStarted, PIString, program);
EVENT2(execFinished, PIString, program, int, exit_code); EVENT2(execFinished, PIString, program, int, exit_code);
bool isExecFinished() const {return exec_finished;} //! \~english Check if attached execution has finished
bool isExecStarted() const {return exec_start;} //! \~russian Проверяет, завершилось ли выполнение процесса
bool isExecFinished() const { return exec_finished; }
//! \~english Check if attached execution has started
//! \~russian Проверяет, запущен ли процесс выполнения
bool isExecStarted() const { return exec_start; }
//! \~english Start detached execution "program" without arguments //! \~english Start detached execution "program" without arguments
//! \~russian //! \~russian Запускает независимое выполнение "program" без аргументов
static void execIndependent(const PIString & program) { execIndependent(program, PIStringList()); } static void execIndependent(const PIString & program) { execIndependent(program, PIStringList()); }
//! \~english Start detached execution "program" with one argument "arg" //! \~english Start detached execution "program" with one argument "arg"
//! \~russian //! \~russian Запускает независимое выполнение "program" с одним аргументом "arg"
static void execIndependent(const PIString & program, const PIString & arg) { execIndependent(program, PIStringList() << arg); } static void execIndependent(const PIString & program, const PIString & arg) { execIndependent(program, PIStringList() << arg); }
//! \~english Start detached execution "program" with arguments "args" //! \~english Start detached execution "program" with arguments "args"
//! \~russian //! \~russian Запускает независимое выполнение "program" с аргументами "args"
static void execIndependent(const PIString & program, const PIStringList & args); static void execIndependent(const PIString & program, const PIStringList & args);
//! \~english Returns application environment //! \~english Returns application environment
//! \~russian //! \~russian Возвращает окружение текущего приложения
static PIStringList currentEnvironment(); static PIStringList currentEnvironment();
//! \~english Returns application process ID //! \~english Returns application process ID
//! \~russian //! \~russian Возвращает ID процесса текущего приложения
static int currentPID(); static int currentPID();
//! \~english Returns variable "variable" value from application environment //! \~english Returns variable "variable" value from application environment
//! \~russian //! \~russian Возвращает значение переменной "variable" из окружения приложения
static PIString getEnvironmentVariable(const PIString & variable); static PIString getEnvironmentVariable(const PIString & variable);
//! \handlers //! \handlers
@@ -162,27 +174,27 @@ public:
//! \fn void exec(const PIString & program) //! \fn void exec(const PIString & program)
//! \brief //! \brief
//! \~english Start attached execution "program" without arguments //! \~english Start attached execution "program" without arguments
//! \~russian //! \~russian Запускает выполнение "program" без аргументов
//! \fn void exec(const PIString & program, const PIStringList & args) //! \fn void exec(const PIString & program, const PIStringList & args)
//! \brief //! \brief
//! \~english Start attached execution "program" with arguments "args" //! \~english Start attached execution "program" with arguments "args"
//! \~russian //! \~russian Запускает выполнение "program" с аргументами "args"
//! \fn void terminate() //! \fn void terminate()
//! \brief //! \brief
//! \~english Immediately terminate attached execution //! \~english Immediately terminate attached execution
//! \~russian //! \~russian Немедленно завершает выполнение
//! \fn bool waitForFinish() //! \fn bool waitForFinish()
//! \brief //! \brief
//! \~english Wait for attached execution finish maximum for 60 seconds //! \~english Wait for attached execution finish maximum for 60 seconds
//! \~russian //! \~russian Ожидает завершения выполнения (максимум 60 секунд)
//! \fn bool waitForFinish(PISystemTime timeout) //! \fn bool waitForFinish(PISystemTime timeout)
//! \brief //! \brief
//! \~english Wait for attached execution finish maximum for "timeout_" //! \~english Wait for attached execution finish maximum for "timeout_"
//! \~russian //! \~russian Ожидает завершения выполнения в течение "timeout_"
//! \} //! \}
//! \events //! \events
@@ -191,12 +203,12 @@ public:
//! \fn void execStarted(PIString program) //! \fn void execStarted(PIString program)
//! \brief //! \brief
//! \~english Raise on attached execution start //! \~english Raise on attached execution start
//! \~russian //! \~russian Генерируется при запуске выполнения
//! \fn void execFinished(PIString program) //! \fn void execFinished(PIString program)
//! \brief //! \brief
//! \~english Raise on attached execution finish //! \~english Raise on attached execution finish
//! \~russian //! \~russian Генерируется при завершении выполнения
//! \} //! \}