1 /* KDevelop Util Library
3 * Copyright 2007 Andreas Pakulat <apaku@gmx.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #ifndef COMMANDEXECUTOR_H
22 #define COMMANDEXECUTOR_H
24 #include <QtCore/QObject>
25 #include <QtCore/QProcess>
26 #include "utilexport.h"
32 * Simplifying the exeuction of a Command through (QK)Process.
34 * This class emits only very basic signals when the process writes something
35 * to stdout or stderr and for signaling completed and failed status.
37 * If you need more fine-grained control use (QK)Process directly and also
38 * check wether you can use \ref KDevelop::ProcessLineMaker to use properly
39 * terminated lines of output.
41 * Also this class provides only asynchronous operation, it doesn't allow to
42 * wait for the program to finish.
44 * @author Andreas Pakulat <apaku@gmx.de>
45 * TODO: Should this be a KJob??
47 class KDEVPLATFORMUTIL_EXPORT CommandExecutor
: public QObject
52 * Create a command using the given executable, arguments and environment
54 * The process is not started immediately, instead start() has to be called.
56 explicit CommandExecutor( const QString
& command
, QObject
* parent
= 0 );
60 * set additional arguments to be used when executing the command
62 void setArguments( const QStringList
& args
);
64 * set additional environment variables to be used when executing the command
66 void setEnvironment( const QMap
<QString
,QString
>& env
);
69 * Sets the working directory of the command
71 void setWorkingDirectory( const QString
& dir
);
74 * start the command, after this has been called signals may be emitted
79 * kill the process, failed() will likely be emitted
84 * set the Command that should be started, now a commandexecutor can be reused
86 void setCommand( const QString
& command
);
89 void receivedStandardError( const QStringList
& );
90 void receivedStandardOutput( const QStringList
& );
94 Q_PRIVATE_SLOT( d
, void procError( QProcess::ProcessError
) )
95 Q_PRIVATE_SLOT( d
, void procFinished( int, QProcess::ExitStatus
) )
96 class CommandExecutorPrivate
* const d
;
97 friend class CommandExecutorPrivate
;