1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qt Designer.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "qapplication.h"
#include "qprocess.h"
#include <stdio.h>
#include <stdlib.h>
/*!
\class QProcess qprocess.h
\brief The QProcess class provides means to start external programs and
control their behavior.
\ingroup ?
A QProcess allows you to start a external program, control its input and
output, etc.
*/
/*!
Constructs a QProcess.
*/
QProcess::QProcess( QObject *parent, const char *name )
: QObject( parent, name )
{
d = new QProcessPrivate( this );
}
/*!
Constructs a QProcess with the given command (but does not start it).
*/
QProcess::QProcess( const QString& com, QObject *parent, const char *name )
: QObject( parent, name )
{
d = new QProcessPrivate( this );
setCommand( com );
}
/*!
Constructs a QProcess with the given command and arguments (but does not
start it).
*/
QProcess::QProcess( const QString& com, const QStringList& args, QObject *parent, const char *name )
: QObject( parent, name )
{
d = new QProcessPrivate( this );
setCommand( com );
setArguments( args );
}
/*!
Destructor; if the process is running it is NOT terminated! Stdin, stdout and
stderr of the process are closed.
*/
QProcess::~QProcess()
{
delete d;
}
/*!
Set the command that should be executed.
*/
void QProcess::setCommand( const QString& com )
{
d->command = com;
}
/*!
Set the arguments for the command. Previous set arguments will be deleted
first.
*/
void QProcess::setArguments( const QStringList& args )
{
d->arguments = args;
}
/*!
Add a argument to the end of the existing list of arguments.
*/
void QProcess::addArgument( const QString& arg )
{
d->arguments.append( arg );
}
/*!
Set a working directory in which the command is executed.
*/
void QProcess::setWorkingDirectory( const QDir& dir )
{
d->workingDir = dir;
}
/*!
\fn bool QProcess::start()
Start the program.
Return TRUE on success, otherwise FALSE.
*/
/*!
\fn bool QProcess::hangUp()
Ask the process to terminate. If this does not work you can try \l kill()
instead.
Return TRUE on success, otherwise FALSE.
*/
/*!
\fn bool QProcess::kill()
Terminate the process. This is not a safe way to end a process; you should
try \l hangUp() first and use this function only if it failed.
Return TRUE on success, otherwise FALSE.
*/
/*!
\fn bool QProcess::isRunning()
Return TRUE if the process is running, otherwise FALSE.
*/
/*!
Return TRUE if the process has exited normally, otherwise FALSE.
*/
bool QProcess::normalExit()
{
// isRunning() has the side effect that it determines the exit status!
if ( isRunning() )
return FALSE;
else
return d->exitNormal;
}
/*!
Return the exit status of the process. This value is only valid if
\l normalExit() is TRUE.
*/
int QProcess::exitStatus()
{
// isRunning() has the side effect that it determines the exit status!
if ( isRunning() )
return 0;
else
return d->exitStat;
}
/*!
\fn void QProcess::dataStdout( const QByteArray& buf )
This signal is emitted if the process wrote data to stdout.
*/
/*!
\fn void QProcess::dataStdout( const QString& buf )
This signal is emitted if the process wrote data to stdout.
*/
/*!
\fn void QProcess::dataStderr( const QByteArray& buf )
This signal is emitted if the process wrote data to stderr.
*/
/*!
\fn void QProcess::dataStderr( const QString& buf )
This signal is emitted if the process wrote data to stderr.
*/
/*!
\fn void QProcess::processExited()
This signal is emitted if the process has exited.
*/
/*!
\fn void QProcess::wroteStdin()
This signal is emitted if the data send to stdin (via \l dataStdin()) was
actually read by the process.
*/
/*!
\fn void QProcess::dataStdin( const QByteArray& buf )
Write data to the stdin of the process. The process may or may not read this
data. If the data gets read, the signal \l wroteStdin() is emitted.
*/
/*!
Write data to the stdin of the process. The string is handled as a text. So
what is written to the stdin is the \l QString::latin1(). The process may or
may not read this data. If the data gets read, the signal \l wroteStdin() is
emitted.
*/
void QProcess::dataStdin( const QString& buf )
{
QByteArray bbuf;
bbuf.duplicate( buf.latin1(), buf.length() );
dataStdin( bbuf );
}
/*!
\fn void QProcess::closeStdin( )
Close stdin.
*/
/*!
\fn void QProcess::socketRead( int fd )
The process has output data to either stdout or stderr.
*/
/*!
\fn void QProcess::socketWrite( int fd )
The process tries to read data from stdin.
*/
|