qprocess.sip 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // qprocess.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtCore Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. %If (PyQt_Process)
  22. class QProcess : public QIODevice
  23. {
  24. %TypeHeaderCode
  25. #include <qprocess.h>
  26. %End
  27. public:
  28. enum ExitStatus
  29. {
  30. NormalExit,
  31. CrashExit,
  32. };
  33. enum ProcessError
  34. {
  35. FailedToStart,
  36. Crashed,
  37. Timedout,
  38. ReadError,
  39. WriteError,
  40. UnknownError,
  41. };
  42. enum ProcessState
  43. {
  44. NotRunning,
  45. Starting,
  46. Running,
  47. };
  48. enum ProcessChannel
  49. {
  50. StandardOutput,
  51. StandardError,
  52. };
  53. enum ProcessChannelMode
  54. {
  55. SeparateChannels,
  56. MergedChannels,
  57. ForwardedChannels,
  58. ForwardedOutputChannel,
  59. ForwardedErrorChannel,
  60. };
  61. explicit QProcess(QObject *parent /TransferThis/ = 0);
  62. virtual ~QProcess();
  63. void start(const QString &program, const QStringList &arguments = {}, QIODeviceBase::OpenMode mode = QIODeviceBase::ReadWrite) /HoldGIL/;
  64. void start(QIODeviceBase::OpenMode mode = QIODeviceBase::ReadWrite) /HoldGIL/;
  65. void startCommand(const QString &command, QIODeviceBase::OpenMode mode = QIODeviceBase::ReadWrite) /HoldGIL/;
  66. QProcess::ProcessChannel readChannel() const;
  67. void setReadChannel(QProcess::ProcessChannel channel);
  68. void closeReadChannel(QProcess::ProcessChannel channel);
  69. void closeWriteChannel();
  70. QString workingDirectory() const;
  71. void setWorkingDirectory(const QString &dir);
  72. QProcess::ProcessError error() const;
  73. QProcess::ProcessState state() const;
  74. bool waitForStarted(int msecs = 30000) /ReleaseGIL/;
  75. virtual bool waitForReadyRead(int msecs = 30000) /ReleaseGIL/;
  76. virtual bool waitForBytesWritten(int msecs = 30000) /ReleaseGIL/;
  77. bool waitForFinished(int msecs = 30000) /ReleaseGIL/;
  78. QByteArray readAllStandardOutput() /ReleaseGIL/;
  79. QByteArray readAllStandardError() /ReleaseGIL/;
  80. int exitCode() const;
  81. QProcess::ExitStatus exitStatus() const;
  82. virtual qint64 bytesToWrite() const;
  83. virtual bool isSequential() const;
  84. virtual void close();
  85. static int execute(const QString &program, const QStringList &arguments = {}) /ReleaseGIL/;
  86. static bool startDetached(const QString &program, const QStringList &arguments = {}, const QString &workingDirectory = QString(), qint64 *pid = 0);
  87. bool startDetached(qint64 *pid = 0);
  88. static QStringList systemEnvironment();
  89. QProcess::ProcessChannelMode processChannelMode() const;
  90. void setProcessChannelMode(QProcess::ProcessChannelMode mode);
  91. void setStandardInputFile(const QString &fileName);
  92. void setStandardOutputFile(const QString &fileName, QIODeviceBase::OpenMode mode = QIODeviceBase::Truncate);
  93. void setStandardErrorFile(const QString &fileName, QIODeviceBase::OpenMode mode = QIODeviceBase::Truncate);
  94. void setStandardOutputProcess(QProcess *destination);
  95. public slots:
  96. void terminate();
  97. void kill();
  98. signals:
  99. void started();
  100. void finished(int exitCode, QProcess::ExitStatus exitStatus = QProcess::NormalExit);
  101. void stateChanged(QProcess::ProcessState state);
  102. void readyReadStandardOutput();
  103. void readyReadStandardError();
  104. void errorOccurred(QProcess::ProcessError error);
  105. protected:
  106. void setProcessState(QProcess::ProcessState state);
  107. virtual SIP_PYOBJECT readData(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/ [qint64 (char *data, qint64 maxlen)];
  108. %MethodCode
  109. // Return the data read or None if there was an error.
  110. if (a0 < 0)
  111. {
  112. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  113. sipIsErr = 1;
  114. }
  115. else
  116. {
  117. char *s = new char[a0];
  118. qint64 len;
  119. Py_BEGIN_ALLOW_THREADS
  120. #if defined(SIP_PROTECTED_IS_PUBLIC)
  121. len = sipSelfWasArg ? sipCpp->QProcess::readData(s, a0) : sipCpp->readData(s, a0);
  122. #else
  123. len = sipCpp->sipProtectVirt_readData(sipSelfWasArg, s, a0);
  124. #endif
  125. Py_END_ALLOW_THREADS
  126. if (len < 0)
  127. {
  128. Py_INCREF(Py_None);
  129. sipRes = Py_None;
  130. }
  131. else
  132. {
  133. sipRes = PyBytes_FromStringAndSize(s, len);
  134. if (!sipRes)
  135. sipIsErr = 1;
  136. }
  137. delete[] s;
  138. }
  139. %End
  140. virtual qint64 writeData(SIP_PYBUFFER) /ReleaseGIL/ [qint64 (const char *data, qint64 len)];
  141. %MethodCode
  142. sipBufferInfoDef bi;
  143. if (sipGetBufferInfo(a0, &bi) > 0)
  144. {
  145. Py_BEGIN_ALLOW_THREADS
  146. #if defined(SIP_PROTECTED_IS_PUBLIC)
  147. sipRes = sipSelfWasArg ?
  148. sipCpp->QProcess::writeData(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len) :
  149. sipCpp->writeData(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len);
  150. #else
  151. sipRes = sipCpp->sipProtectVirt_writeData(sipSelfWasArg, reinterpret_cast<char *>(bi.bi_buf),
  152. bi.bi_len);
  153. #endif
  154. Py_END_ALLOW_THREADS
  155. sipReleaseBufferInfo(&bi);
  156. }
  157. else
  158. {
  159. sipIsErr = 1;
  160. }
  161. %End
  162. public:
  163. void setProcessEnvironment(const QProcessEnvironment &environment);
  164. QProcessEnvironment processEnvironment() const;
  165. QString program() const;
  166. void setProgram(const QString &program);
  167. QStringList arguments() const;
  168. void setArguments(const QStringList &arguments);
  169. %If (Windows)
  170. void setNativeArguments(const QString &arguments);
  171. %End
  172. %If (Windows)
  173. QString nativeArguments() const;
  174. %End
  175. virtual bool open(QIODeviceBase::OpenMode mode = QIODeviceBase::ReadWrite) /ReleaseGIL/;
  176. enum InputChannelMode
  177. {
  178. ManagedInputChannel,
  179. ForwardedInputChannel,
  180. };
  181. QProcess::InputChannelMode inputChannelMode() const;
  182. void setInputChannelMode(QProcess::InputChannelMode mode);
  183. static QString nullDevice();
  184. qint64 processId() const;
  185. %If (Qt_6_6_0 -)
  186. %If (Linux || macOS)
  187. enum class UnixProcessFlag : quint32
  188. {
  189. ResetSignalHandlers,
  190. IgnoreSigPipe,
  191. CloseFileDescriptors,
  192. UseVFork,
  193. CreateNewSession,
  194. DisconnectControllingTerminal,
  195. ResetIds,
  196. DisableCoreDumps,
  197. };
  198. %End
  199. %End
  200. %If (Qt_6_6_0 -)
  201. %If (Linux || macOS)
  202. typedef QFlags<QProcess::UnixProcessFlag> UnixProcessFlags;
  203. %End
  204. %End
  205. %If (Qt_6_6_0 -)
  206. %If (Linux || macOS)
  207. struct UnixProcessParameters
  208. {
  209. %TypeHeaderCode
  210. #include <qprocess.h>
  211. %End
  212. QProcess::UnixProcessFlags flags;
  213. int lowestFileDescriptorToClose;
  214. };
  215. %End
  216. %End
  217. %If (Qt_6_6_0 -)
  218. %If (Linux || macOS)
  219. QProcess::UnixProcessParameters unixProcessParameters() const;
  220. %End
  221. %End
  222. %If (Qt_6_6_0 -)
  223. %If (Linux || macOS)
  224. void setUnixProcessParameters(QProcess::UnixProcessFlags flagsOnly);
  225. %End
  226. %End
  227. %If (Qt_6_6_0 -)
  228. %If (Linux || macOS)
  229. void setUnixProcessParameters(const QProcess::UnixProcessParameters &params);
  230. %End
  231. %End
  232. };
  233. %End
  234. %If (PyQt_Process)
  235. class QProcessEnvironment
  236. {
  237. %TypeHeaderCode
  238. #include <qprocess.h>
  239. %End
  240. public:
  241. %If (Qt_6_3_0 -)
  242. enum Initialization
  243. {
  244. InheritFromParent,
  245. };
  246. %End
  247. %If (Qt_6_3_0 -)
  248. QProcessEnvironment(QProcessEnvironment::Initialization);
  249. %End
  250. QProcessEnvironment();
  251. QProcessEnvironment(const QProcessEnvironment &other);
  252. ~QProcessEnvironment();
  253. %If (- Qt_6_8_0)
  254. bool operator==(const QProcessEnvironment &other) const;
  255. %End
  256. %If (- Qt_6_8_0)
  257. bool operator!=(const QProcessEnvironment &other) const;
  258. %End
  259. bool isEmpty() const;
  260. void clear();
  261. bool contains(const QString &name) const;
  262. void insert(const QString &name, const QString &value);
  263. void insert(const QProcessEnvironment &e);
  264. void remove(const QString &name);
  265. QString value(const QString &name, const QString &defaultValue = QString()) const;
  266. QStringList toStringList() const;
  267. static QProcessEnvironment systemEnvironment();
  268. QStringList keys() const;
  269. void swap(QProcessEnvironment &other /Constrained/);
  270. %If (Qt_6_3_0 -)
  271. bool inheritsFromParent() const;
  272. %End
  273. };
  274. %End
  275. %If (Qt_6_8_0 -)
  276. bool operator!=(const QProcessEnvironment &lhs, const QProcessEnvironment &rhs);
  277. %End
  278. %If (Qt_6_8_0 -)
  279. bool operator==(const QProcessEnvironment &lhs, const QProcessEnvironment &rhs);
  280. %End