KDECore
Go to the documentation of this file.
40 # define STD_OUTPUT_HANDLE 1
41 # define STD_ERROR_HANDLE 2
52 HANDLE h = GetStdHandle(fd);
55 WriteFile(h, buf.data(), buf.size(), &wr, 0);
58 fwrite(buf.data(), 1, buf.size(), (FILE*)fd);
63 int ret = ::write(fd, buf.data() + off, buf.size() - off);
70 }
while (off < buf.size());
78 QProcess::ProcessChannel oc = q->readChannel();
79 q->setReadChannel(good);
81 q->setReadChannel(oc);
87 forwardStd(KProcess::StandardOutput, STD_OUTPUT_HANDLE);
89 forwardStd(KProcess::StandardOutput, (
int)stdout);
96 forwardStd(KProcess::StandardError, STD_ERROR_HANDLE);
98 forwardStd(KProcess::StandardError, (
int)stderr);
131 d->outputChannelMode = mode;
132 disconnect(
this, SIGNAL(readyReadStandardOutput()));
133 disconnect(
this, SIGNAL(readyReadStandardError()));
136 connect(
this, SIGNAL(readyReadStandardError()), SLOT(_k_forwardStderr()));
139 connect(
this, SIGNAL(readyReadStandardOutput()), SLOT(_k_forwardStdout()));
142 QProcess::setProcessChannelMode((ProcessChannelMode)mode);
145 QProcess::setProcessChannelMode(QProcess::SeparateChannels);
152 return d->outputChannelMode;
162 #define DUMMYENV "_KPROCESS_DUMMY_="
173 env = systemEnvironment();
174 env.removeAll(QString::fromLatin1(
DUMMYENV));
177 fname.append(QLatin1Char(
'='));
178 for (QStringList::Iterator it = env.begin(); it != env.end(); ++it)
179 if ((*it).startsWith(fname)) {
181 *it = fname.append(value);
186 env.append(fname.append(value));
194 env = systemEnvironment();
195 env.removeAll(QString::fromLatin1(
DUMMYENV));
198 fname.append(QLatin1Char(
'='));
199 for (QStringList::Iterator it = env.begin(); it != env.end(); ++it)
200 if ((*it).startsWith(fname)) {
203 env.append(QString::fromLatin1(
DUMMYENV));
224 Q_ASSERT( !argv.isEmpty() );
226 d->prog = d->args.takeFirst();
236 if (d->prog.isEmpty())
247 if (d->prog.isEmpty())
274 if (!d->prog.isEmpty()) {
275 d->args.removeFirst();
287 # if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) && !defined(__GNU__)
291 d->prog = QFile::symLinkTarget(QString::fromLatin1(
"/bin/sh"));
292 if (d->prog.isEmpty()) {
295 if (d->prog.isEmpty()) {
297 if (d->prog.isEmpty()) {
299 if (d->prog.isEmpty()) {
301 if (d->prog.isEmpty())
303 d->prog = QString::fromLatin1(
"/bin/sh");
309 d->prog = QString::fromLatin1(
"/bin/sh");
312 d->args << QString::fromLatin1(
"-c") << cmd;
319 WCHAR sysdir[MAX_PATH + 1];
320 UINT size = GetSystemDirectoryW(sysdir, MAX_PATH + 1);
321 d->prog = QString::fromUtf16((
const ushort *) sysdir, size);
322 d->prog += QLatin1String(
"\\cmd.exe");
323 setNativeArguments(QLatin1String(
"/V:OFF /S /C \"") + cmd + QLatin1Char(
'"'));
325 d->prog = QLatin1String(
"\\windows\\cmd.exe");
326 setNativeArguments(QLatin1String(
"/S /C \"") + cmd + QLatin1Char(
'"'));
336 argv.prepend(d->prog);
344 QProcess::start(d->prog, d->args, d->openMode);
350 if (!waitForFinished(msecs)) {
355 return (exitStatus() == QProcess::NormalExit) ? exitCode() : -1;
379 if (!QProcess::startDetached(d->prog, d->args, workingDirectory(), &
pid))
388 if (!QProcess::startDetached(exe, args,
QString(), &
pid))
397 QString prog = args.takeFirst();
410 #include "kprocess.moc"
KProcess & operator<<(const QString &arg)
Append an element to the command line argument list for this process.
void setEnv(const QString &name, const QString &value, bool overwrite=true)
Adds the variable name to the process' environment.
@ OnlyStdoutChannel
Only standard output is handled; standard error is forwarded.
void setShellCommand(const QString &cmd)
Set a command to execute through a shell (a POSIX sh on *NIX and cmd.exe on Windows).
Errors
Status codes from splitArgs()
int pid() const
Obtain the process' ID as known to the system.
OutputChannelMode outputChannelMode() const
Query how the output channels of the child process are handled.
void forwardStd(KProcess::ProcessChannel good, int fd)
void writeAll(const QByteArray &buf, int fd)
void setOutputChannelMode(OutputChannelMode mode)
Set how to handle the output channels of the child process.
void unsetEnv(const QString &name)
Removes the variable name from the process' environment.
QStringList program() const
Obtain the currently set program and arguments.
KProcess(QObject *parent=0)
Constructor.
void start()
Start the process.
void clearProgram()
Clear the program and command line argument list.
static QString findExe(const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
Finds the executable in the system path.
KProcessPrivate *const d_ptr
virtual ~KProcess()
Destructor.
@ ForwardedChannels
Both standard output and standard error are forwarded to the parent process' respective channel.
QStringList splitArgs(const QString &cmd, Options flags=NoOptions, Errors *err=0)
Splits cmd according to system shell word splitting and quoting rules.
void clearEnvironment()
Empties the process' environment.
@ OnlyStderrChannel
Only standard error is handled; standard output is forwarded.
int execute(int msecs=-1)
Start the process, wait for it to finish, and return the exit code.
int startDetached()
Start the process and detach from it.
@ AbortOnMeta
Put the parser into full shell mode and bail out if a too complex construct is encoutered.
@ TildeExpand
Perform tilde expansion.
OutputChannelMode
Modes in which the output channels can be opened.
void setProgram(const QString &exe, const QStringList &args=QStringList())
Set the program and the command line arguments.
void setNextOpenMode(QIODevice::OpenMode mode)
Set the QIODevice open mode the process will be opened in.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jan 19 2020 00:00:00 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.