org.kde.koala
Class KProcess

java.lang.Object
  extended by org.kde.qt.Qt
      extended by org.kde.qt.QObject
          extended by org.kde.koala.KProcess
All Implemented Interfaces:
org.kde.qt.QtSupport
Direct Known Subclasses:
KProcIO, KShellProcess

public class KProcess
extends org.kde.qt.QObject

Child process invocation, monitoring and control.

  • General usage and features:
  • This class allows a KDE application to start child processes without having to worry about UNX signal handling issues and zombie process reaping. Basically, this class distinguishes three different ways of running child processes:
  • DontCare -- The child process is invoked and both the child process and the parent process continue concurrently.
  • The process is started in an own session (see setsid(2)).
  • NotifyOnExit -- The child process is invoked and both the child and the parent process run concurrently.
  • When the child process exits, the KProcess instance corresponding to it emits the Qt signal processExited(). Since this signal is not emitted from within a UNX signal handler, arbitrary function calls can be made. Be aware: When the KProcess object gets destructed, the child process will be killed if it is still running! This means in particular, that it usually makes no sense to use a KProcess on the stack with NotifyOnExit.
  • OwnGroup -- like NotifyOnExit, but the child process is started in an own process group (and an own session, FWIW). The behavior of kill() changes to killing the whole process group - this makes this mode useful for implementing primitive job management. It can be used to work around broken wrapper scripts that don't propagate signals to the "real" program. However, use this with care, as you disturb the shell's job management if your program is started from the command line.
  • Block -- The child process starts and the parent process is suspended until the child process exits. (Really not recommended for programs with a GUI.) In this mode the parent can read the child's output, but can't send it any input.
  • KProcess also provides several functions for determining the exit status and the pid of the child process it represents. Furthermore it is possible to supply command-line arguments to the process in a clean fashion (no null-terminated stringlists and such...) A small usage example:
       KProcess proc = new KProcess;
       proc << "my_executable";
       proc << "These" << "are" << "the" << "command" << "line" << "args";
       QApplication.connect(proc, SIGNAL("processExited(KProcess )"),
                             pointer_to_my_object, SLOT("my_objects_slot(KProcess )"));
       proc.start();
     
    This will start "my_executable" with the commandline arguments "These"... When the child process exits, the slot will be invoked.
  • Communication with the child process:
  • KProcess supports communication with the child process through stdin/stdout/stderr. The following functions are provided for getting data from the child process or sending data to the child's stdin (For more information, have a look at the documentation of each function):
  • writeStdin() -- Transmit data to the child process' stdin. When all data was sent, the signal wroteStdin() is emitted.
  • When data arrives at stdout or stderr, the signal receivedStdout() resp. receivedStderr() is emitted.
  • You can shut down individual communication channels with closeStdin(), closeStdout(), and closeStderr(), resp.
  • See KProcessSignals for signals emitted by KProcess

    Author:
    Christian Czezatke e9025461@student.tuwien.ac.at
    See Also:
    KProcIO

    Field Summary
    static int All
               
    static int AllOutput
               
    static int Block
               
    static int DontCare
              Run-modes for a child process.
    static int NoCommunication
              Modes in which the communication channel can be opened.
    static int NoRead
               
    static int NotifyOnExit
               
    static int OwnGroup
               
    static int PrioHigh
               
    static int PrioHigher
               
    static int PrioHighest
               
    static int PrioLow
               
    static int PrioLower
               
    static int PrioLowest
              More or less intuitive constants for use with setPriority().
    static int PrioNormal
               
    static int Stderr
               
    static int Stdin
               
    static int Stdout
               
     
    Fields inherited from class org.kde.qt.Qt
    AlignAuto, AlignBottom, AlignCenter, AlignHCenter, AlignHorizontal_Mask, AlignJustify, AlignLeft, AlignRight, AlignTop, AlignVCenter, AlignVertical_Mask, AlphaDither_Mask, ALT, AltButton, AnchorHref, AnchorName, AndNotROP, AndROP, ArrowCursor, Ascending, ASCII_ACCEL, AutoColor, AutoDither, AutoText, AvoidDither, BDiagPattern, BeginsWith, BevelJoin, BitmapCursor, BlankCursor, Bottom, BottomLeft, BottomRight, BreakAnywhere, BusyCursor, CaseSensitive, ClearROP, ColorMode_Mask, ColorOnly, Contains, ControlButton, CopyROP, CrossCursor, CrossPattern, CTRL, CustomPattern, DashDotDotLine, DashDotLine, DashLine, Dense1Pattern, Dense2Pattern, Dense3Pattern, Dense4Pattern, Dense5Pattern, Dense6Pattern, Dense7Pattern, Descending, DiagCrossPattern, DiffuseAlphaDither, DiffuseDither, Dither_Mask, DitherMode_Mask, DockBottom, DockLeft, DockMinimized, DockRight, DockTop, DockTornOff, DockUnmanaged, DontClip, DontPrint, DotLine, DownArrow, EndsWith, EraseROP, ExactMatch, ExpandTabs, FDiagPattern, FixedColor, FixedPixmap, FlatCap, ForbiddenCursor, HiEnglishUnit, HiMetricUnit, Horizontal, HorPattern, IbeamCursor, Identical, IncludeTrailingSpaces, ISODate, Key_0, Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_A, Key_aacute, Key_Aacute, Key_acircumflex, Key_Acircumflex, Key_acute, Key_adiaeresis, Key_Adiaeresis, Key_ae, Key_AE, Key_agrave, Key_Agrave, Key_Alt, Key_Ampersand, Key_Any, Key_Apostrophe, Key_aring, Key_Aring, Key_AsciiCircum, Key_AsciiTilde, Key_Asterisk, Key_At, Key_atilde, Key_Atilde, Key_B, Key_Back, Key_Backslash, Key_Backspace, Key_BackSpace, Key_Backtab, Key_BackTab, Key_Bar, Key_BassBoost, Key_BassDown, Key_BassUp, Key_BraceLeft, Key_BraceRight, Key_BracketLeft, Key_BracketRight, Key_brokenbar, Key_C, Key_CapsLock, Key_ccedilla, Key_Ccedilla, Key_cedilla, Key_cent, Key_Clear, Key_Colon, Key_Comma, Key_Control, Key_copyright, Key_currency, Key_D, Key_degree, Key_Delete, Key_diaeresis, Key_Direction_L, Key_Direction_R, Key_division, Key_Dollar, Key_Down, Key_E, Key_eacute, Key_Eacute, Key_ecircumflex, Key_Ecircumflex, Key_ediaeresis, Key_Ediaeresis, Key_egrave, Key_Egrave, Key_End, Key_Enter, Key_Equal, Key_Escape, Key_eth, Key_ETH, Key_Exclam, Key_exclamdown, Key_F, Key_F1, Key_F10, Key_F11, Key_F12, Key_F13, Key_F14, Key_F15, Key_F16, Key_F17, Key_F18, Key_F19, Key_F2, Key_F20, Key_F21, Key_F22, Key_F23, Key_F24, Key_F25, Key_F26, Key_F27, Key_F28, Key_F29, Key_F3, Key_F30, Key_F31, Key_F32, Key_F33, Key_F34, Key_F35, Key_F4, Key_F5, Key_F6, Key_F7, Key_F8, Key_F9, Key_Favorites, Key_Forward, Key_G, Key_Greater, Key_guillemotleft, Key_guillemotright, Key_H, Key_Help, Key_Home, Key_HomePage, Key_Hyper_L, Key_Hyper_R, Key_hyphen, Key_I, Key_iacute, Key_Iacute, Key_icircumflex, Key_Icircumflex, Key_idiaeresis, Key_Idiaeresis, Key_igrave, Key_Igrave, Key_Insert, Key_J, Key_K, Key_L, Key_Launch0, Key_Launch1, Key_Launch2, Key_Launch3, Key_Launch4, Key_Launch5, Key_Launch6, Key_Launch7, Key_Launch8, Key_Launch9, Key_LaunchA, Key_LaunchB, Key_LaunchC, Key_LaunchD, Key_LaunchE, Key_LaunchF, Key_LaunchMail, Key_LaunchMedia, Key_Left, Key_Less, Key_M, Key_macron, Key_masculine, Key_MediaLast, Key_MediaNext, Key_MediaPlay, Key_MediaPrev, Key_MediaRecord, Key_MediaStop, Key_Menu, Key_Meta, Key_Minus, Key_mu, Key_multiply, Key_N, Key_Next, Key_nobreakspace, Key_notsign, Key_ntilde, Key_Ntilde, Key_NumberSign, Key_NumLock, Key_O, Key_oacute, Key_Oacute, Key_ocircumflex, Key_Ocircumflex, Key_odiaeresis, Key_Odiaeresis, Key_ograve, Key_Ograve, Key_onehalf, Key_onequarter, Key_onesuperior, Key_Ooblique, Key_OpenUrl, Key_ordfeminine, Key_oslash, Key_otilde, Key_Otilde, Key_P, Key_PageDown, Key_PageUp, Key_paragraph, Key_ParenLeft, Key_ParenRight, Key_Pause, Key_Percent, Key_Period, Key_periodcentered, Key_Plus, Key_plusminus, Key_Print, Key_Prior, Key_Q, Key_Question, Key_questiondown, Key_QuoteDbl, Key_QuoteLeft, Key_R, Key_Refresh, Key_registered, Key_Return, Key_Right, Key_S, Key_ScrollLock, Key_Search, Key_section, Key_Semicolon, Key_Shift, Key_Slash, Key_Space, Key_ssharp, Key_Standby, Key_sterling, Key_Stop, Key_Super_L, Key_Super_R, Key_SysReq, Key_T, Key_Tab, Key_thorn, Key_THORN, Key_threequarters, Key_threesuperior, Key_TrebleDown, Key_TrebleUp, Key_twosuperior, Key_U, Key_uacute, Key_Uacute, Key_ucircumflex, Key_Ucircumflex, Key_udiaeresis, Key_Udiaeresis, Key_ugrave, Key_Ugrave, Key_Underscore, Key_unknown, Key_Up, Key_V, Key_VolumeDown, Key_VolumeMute, Key_VolumeUp, Key_W, Key_X, Key_Y, Key_yacute, Key_Yacute, Key_ydiaeresis, Key_yen, Key_Z, KeyButtonMask, Keypad, LastCursor, LastROP, Left, LeftArrow, LeftButton, LocalDate, LocalTime, LoEnglishUnit, LogText, LoMetricUnit, MacStyle, META, MetaButton, MidButton, Minimized, MiterJoin, MODIFIER_MASK, MonoOnly, MotifStyle, MouseButtonMask, MPenCapStyle, MPenJoinStyle, MPenStyle, MV_10_DOT_0, MV_10_DOT_1, MV_10_DOT_2, MV_10_DOT_3, MV_10_DOT_4, MV_9, MV_CHEETAH, MV_JAGUAR, MV_PANTHER, MV_PUMA, MV_TIGER, MV_Unknown, NandROP, NoAccel, NoAlpha, NoBackground, NoBrush, NoButton, NoMatch, NoPen, NopROP, NorROP, NotAndROP, NotCopyROP, NotEraseROP, NotOrROP, NotROP, NotXorROP, OpaqueMode, OrderedAlphaDither, OrderedDither, OrNotROP, OrROP, Overline, PaletteBackground, PaletteBase, PaletteBrightText, PaletteButton, PaletteButtonText, PaletteDark, PaletteForeground, PaletteHighlight, PaletteHighlightedText, PaletteLight, PaletteLink, PaletteLinkVisited, PaletteMid, PaletteMidlight, PaletteShadow, PaletteText, PartialMatch, PixelUnit, PlainText, PMStyle, PointingHandCursor, PreferDither, RichText, Right, RightArrow, RightButton, RoundCap, RoundJoin, SetROP, SHIFT, ShiftButton, ShowPrefix, SingleLine, SizeAllCursor, SizeBDiagCursor, SizeFDiagCursor, SizeHorCursor, SizeVerCursor, SolidLine, SolidPattern, SplitHCursor, SplitVCursor, SquareCap, StrikeOut, TextDate, ThresholdAlphaDither, ThresholdDither, Top, TopLeft, TopRight, TornOff, TransparentMode, TwipsUnit, UI_AnimateCombo, UI_AnimateMenu, UI_AnimateToolBox, UI_AnimateTooltip, UI_FadeMenu, UI_FadeTooltip, UI_General, Underline, UNICODE_ACCEL, Unmanaged, UpArrow, UpArrowCursor, UTC, VerPattern, Vertical, WaitCursor, WDestructiveClose, WGroupLeader, WhatsThisCursor, Win3Style, WindowActive, WindowFullScreen, WindowMaximized, WindowMinimized, WindowNoState, WindowsStyle, WMacDrawer, WMacNoSheet, WMouseNoMask, WNoAutoErase, WNoMousePropagation, WNorthWestGravity, WordBreak, WPaintClever, WPaintDesktop, WPaintUnclipped, WRepaintNoErase, WResizeNoErase, WShowModal, WState_AutoMask, WState_BlockUpdates, WState_CompressKeys, WState_ConfigPending, WState_Created, WState_CreatedHidden, WState_Disabled, WState_DND, WState_Exposed, WState_ForceDisabled, WState_ForceHide, WState_FullScreen, WState_HasMouse, WState_InPaintEvent, WState_Maximized, WState_Minimized, WState_MouseTracking, WState_OwnCursor, WState_OwnSizePolicy, WState_Polished, WState_Reparented, WState_Reserved0, WState_Resized, WState_Visible, WStaticContents, WStyle_ContextHelp, WStyle_Customize, WStyle_Dialog, WStyle_DialogBorder, WStyle_Mask, WStyle_Maximize, WStyle_Minimize, WStyle_MinMax, WStyle_NoBorder, WStyle_NoBorderEx, WStyle_NormalBorder, WStyle_Reserved, WStyle_Splash, WStyle_StaysOnTop, WStyle_SysMenu, WStyle_Title, WStyle_Tool, WSubWindow, WType_Desktop, WType_Dialog, WType_Mask, WType_Modal, WType_Popup, WType_TopLevel, WV_2000, WV_2003, WV_32s, WV_95, WV_98, WV_CE, WV_CE_based, WV_CENET, WV_DOS_based, WV_Me, WV_NT, WV_NT_based, WV_XP, WWinOwnDC, WX11BypassWM, X11ParentRelative, XorROP
     
    Constructor Summary
      KProcess()
              Constructor
    protected KProcess(java.lang.Class dummy)
               
      KProcess(org.kde.qt.QObject parent)
               
      KProcess(org.kde.qt.QObject parent, java.lang.String name)
              Constructor
     
    Method Summary
    protected  int childError(int fdno)
              Called by slotChildError() this function copies data arriving from the child process' stderr to the respective buffer and emits the signal receivedStderr().
    protected  int childOutput(int fdno)
              Called by slotChildOutput() this function copies data arriving from the child process' stdout to the respective buffer and emits the signal receivedStdout().
     java.lang.String className()
               
     void clearArguments()
              Clear a command line argument list that has been set by using operator<<.
     void closeAll()
               
     boolean closePty()
              Deletes the optional utmp entry and closes the pty.
     boolean closeStderr()
              Shuts down the Stderr communication link.
     boolean closeStdin()
              Shuts down the Stdin communication link.
     boolean closeStdout()
              Shuts down the Stdout communication link.
    protected  void commClose()
              Cleans up the communication links to the child after it has exited.
    protected  int commSetupDoneC()
              Called right after a (successful) fork(), but before an exec() on the child process' side.
    protected  int commSetupDoneP()
              Called right after a (successful) fork() on the parent side.
     boolean coreDumped()
              Checks whether a killed process dumped core.
     void detach()
              Detaches KProcess from child process.
     void dispose()
              Delete the wrapped C++ instance ahead of finalize()
     int exitSignal()
              Returns the signal the process was killed by.
     int exitStatus()
              Returns the exit status of the process.
    protected  void finalize()
              Deletes the wrapped C++ instance
     boolean isDisposed()
              Has the wrapped C++ instance been deleted?
     boolean isRunning()
              Checks whether the process is running.
     boolean kill()
               
     boolean kill(int signo)
              Stop the process (by sending it a signal).
     org.kde.qt.QMetaObject metaObject()
               
     boolean normalExit()
              Checks whether the process exited cleanly.
     KProcess op_write(java.lang.String arg)
              Sets the executable and the command line argument list for this process.
     KProcess op_write(java.lang.String[] args)
              Sets the executable and the command line argument list for this process, in a single method call, or add a list of arguments.
     int pid()
              Returns the process id of the process.
    protected  void processHasExited(int state)
              Immediately called after a successfully started process in NotifyOnExit mode has exited.
    static java.lang.String quote(java.lang.String arg)
              This function can be used to quote an argument string such that the shell processes it properly.
     void resume()
              Resume processing of data from stdout of the child process.
     boolean runPrivileged()
              Returns whether the started process will drop any setuid/setgid privileges or whether it will keep them.
    protected  void setBinaryExecutable(java.lang.String filename)
              Specify the actual executable that should be started (first argument to execve) Normally the the first argument is the executable but you can override that with this function.
     void setEnvironment(java.lang.String name, java.lang.String value)
              Adds the variable name to the process' environment.
     boolean setPriority(int prio)
              Sets the scheduling priority of the process.
     void setRunPrivileged(boolean keepPrivileges)
              Controls whether the started process should drop any setuid/setgid privileges or whether it should keep them.
    protected  int setupCommunication(int comm)
              This function is called from start() right before a fork() takes place.
    protected  void setupEnvironment()
              Sets up the environment according to the data passed via setEnvironment()
     void setUseShell(boolean useShell)
               
     void setUseShell(boolean useShell, java.lang.String shell)
              Specify whether to start the command via a shell or directly.
     void setWorkingDirectory(java.lang.String dir)
              Changes the current working directory (CWD) of the process to be started.
     boolean signalled()
              Checks whether the process was killed by a signal.
    protected  void slotChildError(int fdno)
              This slot gets activated when data from the child's stderr arrives.
    protected  void slotChildOutput(int fdno)
              This slot gets activated when data from the child's stdout arrives.
    protected  void slotSendData(int dummy)
              Called when another bulk of data can be sent to the child's stdin.
     boolean start()
               
     boolean start(int runmode)
               
     boolean start(int runmode, int comm)
              Starts the process.
     void suspend()
              Suspend processing of data from stdout of the child process.
     boolean waitThread()
               
     boolean waitThread(int timeout)
              Suspend execution of the current thread until the child process dies or the timeout hits.
     boolean writeStdin(java.lang.String buffer, int buflen)
              Transmit data to the child process' stdin.
     
    Methods inherited from class org.kde.qt.QObject
    activate_filters, activate_signal_bool, activate_signal, activate_signal, activate_signal, activate_signal, blockSignals, checkConnectArgs, child, child, child, childEvent, children, connect, connect, connectInternal, connectNotify, customEvent, deleteLater, disconnect, disconnect, disconnect, disconnect, disconnect, disconnect, disconnect, disconnectInternal, disconnectNotify, dumpObjectInfo, dumpObjectTree, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, emit, event, eventFilter, highPriority, i18n, inherits, insertChild, installEventFilter, isA, isWidgetType, killTimer, killTimers, name, name, normalizeSignalSlot, objectTrees, parent, property, queryList, queryList, queryList, queryList, queryList, registerUserData, removeChild, removeEventFilter, sender, setName, setProperty, signalsBlocked, startTimer, timerEvent, tr, tr
     
    Methods inherited from class org.kde.qt.Qt
    arrowCursor, bin, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, bitBlt, black, blankCursor, blue, color0, color1, copyBlt, copyBlt, copyBlt, copyBlt, copyBlt, crossCursor, cyan, darkBlue, darkCyan, darkGray, darkGreen, darkMagenta, darkRed, darkYellow, dec, dynamicCast, endl, flush, forbiddenCursor, fromUtf8, gray, green, hex, ibeamCursor, lightGray, magenta, oct, op_div, op_div, op_div, op_div, op_equals, op_equals, op_equals, op_equals, op_minus, op_minus, op_minus, op_mult, op_mult, op_mult, op_mult, op_mult, op_mult, op_mult, op_mult, op_mult, op_not_equals, op_not_equals, op_not_equals, op_not_equals, op_plus, op_plus, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_read, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, op_write, pointingHandCursor, qAlpha, qApp, qAppName, qBlue, qCompress, qCompress, qDebug, qDebug, qDrawArrow, qDrawItem, qDrawItem, qDrawItem, qDrawPlainRect, qDrawPlainRect, qDrawPlainRect, qDrawPlainRect, qDrawPlainRect, qDrawPlainRect, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadeLine, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadePanel, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawShadeRect, qDrawWinButton, qDrawWinButton, qDrawWinButton, qDrawWinButton, qDrawWinButton, qDrawWinButton, qDrawWinPanel, qDrawWinPanel, qDrawWinPanel, qDrawWinPanel, qDrawWinPanel, qDrawWinPanel, qFatal, qFatal, qGLVersion, qGray, qGray, qGreen, qInitNetworkProtocols, qInstallPath, qInstallPathBins, qInstallPathData, qInstallPathDocs, qInstallPathHeaders, qInstallPathLibs, qInstallPathPlugins, qInstallPathSysconf, qInstallPathTranslations, qItemRect, qItemRect, qObsolete, qObsolete, qObsolete, qRed, qRgb, qRgba, qRound, qSharedBuild, qSuppressObsoleteWarnings, qSuppressObsoleteWarnings, qSysInfo, qSystemWarning, qSystemWarning, qUncompress, qUncompress, qVersion, qWarning, qWarning, red, reset, SIGNAL, sizeAllCursor, sizeBDiagCursor, sizeFDiagCursor, sizeHorCursor, sizeVerCursor, SLOT, splitHCursor, splitVCursor, upArrowCursor, waitCursor, whatsThisCursor, white, ws, yellow
     
    Methods inherited from class java.lang.Object
    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    PrioLowest

    public static final int PrioLowest
    More or less intuitive constants for use with setPriority().

    See Also:
    Constant Field Values

    PrioLow

    public static final int PrioLow
    See Also:
    Constant Field Values

    PrioLower

    public static final int PrioLower
    See Also:
    Constant Field Values

    PrioNormal

    public static final int PrioNormal
    See Also:
    Constant Field Values

    PrioHigher

    public static final int PrioHigher
    See Also:
    Constant Field Values

    PrioHigh

    public static final int PrioHigh
    See Also:
    Constant Field Values

    PrioHighest

    public static final int PrioHighest
    See Also:
    Constant Field Values

    NoCommunication

    public static final int NoCommunication
    Modes in which the communication channel can be opened. If communication for more than one channel is required, the values have to be or'ed together, for example to get communication with stdout as well as with stdin, you would specify Stdin | Stdout If NoRead is specified in conjunction with Stdout, no data is actually read from Stdout but only the signal receivedStdout(int fd, int &len) is emitted.

    See Also:
    Constant Field Values

    Stdin

    public static final int Stdin
    See Also:
    Constant Field Values

    Stdout

    public static final int Stdout
    See Also:
    Constant Field Values

    Stderr

    public static final int Stderr
    See Also:
    Constant Field Values

    AllOutput

    public static final int AllOutput
    See Also:
    Constant Field Values

    All

    public static final int All
    See Also:
    Constant Field Values

    NoRead

    public static final int NoRead
    See Also:
    Constant Field Values

    DontCare

    public static final int DontCare
    Run-modes for a child process.

    See Also:
    Constant Field Values

    NotifyOnExit

    public static final int NotifyOnExit
    See Also:
    Constant Field Values

    Block

    public static final int Block
    See Also:
    Constant Field Values

    OwnGroup

    public static final int OwnGroup
    See Also:
    Constant Field Values
    Constructor Detail

    KProcess

    protected KProcess(java.lang.Class dummy)

    KProcess

    public KProcess(org.kde.qt.QObject parent,
                    java.lang.String name)
    Constructor


    KProcess

    public KProcess(org.kde.qt.QObject parent)

    KProcess

    public KProcess()
    Constructor

    Method Detail

    metaObject

    public org.kde.qt.QMetaObject metaObject()
    Overrides:
    metaObject in class org.kde.qt.QObject

    className

    public java.lang.String className()
    Overrides:
    className in class org.kde.qt.QObject

    op_write

    public KProcess op_write(java.lang.String arg)
    Sets the executable and the command line argument list for this process. For example, doing an "ls -l /usr/local/bin" can be achieved by:
                      KProcess p;
                      ...
                      p << "ls" << "-l" << "/usr/local/bin"
                      

    Parameters:
    arg - the argument to add
    Returns:
    a reference to this KProcess

    op_write

    public KProcess op_write(java.lang.String[] args)
    Sets the executable and the command line argument list for this process, in a single method call, or add a list of arguments.

    Parameters:
    args - the arguments to add
    Returns:
    a reference to this KProcess

    clearArguments

    public void clearArguments()
    Clear a command line argument list that has been set by using operator<<.


    start

    public boolean start(int runmode,
                         int comm)
    Starts the process. For a detailed description of the various run modes and communication semantics, have a look at the general description of the KProcess class. Note that if you use setUsePty( Stdout | Stderr, \ ), you cannot use Stdout | Stderr here - instead, use Stdout only to receive the mixed output. The following problems could cause this function to return false:
  • The process is already running.
  • The command line argument list is empty.
  • The the comm parameter is incompatible with the selected pty usage.
  • The starting of the process failed (could not fork).
  • The executable was not found.
  • Parameters:
    runmode - The Run-mode for the process.
    comm - Specifies which communication links should be established to the child process (stdin/stdout/stderr). By default, no communication takes place and the respective communication signals will never get emitted.
    Returns:
    true on success, false on error (see above for error conditions)

    start

    public boolean start(int runmode)

    start

    public boolean start()

    kill

    public boolean kill(int signo)
    Stop the process (by sending it a signal).

    Parameters:
    signo - The signal to send. The default is SIGTERM.
    Returns:
    true if the signal was delivered successfully.

    kill

    public boolean kill()

    isRunning

    public boolean isRunning()
    Checks whether the process is running.

    Returns:
    true if the process is (still) considered to be running

    pid

    public int pid()
    Returns the process id of the process. If it is called after the process has exited, it returns the process id of the last child process that was created by this instance of KProcess. Calling it before any child process has been started by this KProcess instance causes pid() to return 0.

    Returns:
    the pid of the process or 0 if no process has been started yet.

    suspend

    public void suspend()
    Suspend processing of data from stdout of the child process.


    resume

    public void resume()
    Resume processing of data from stdout of the child process.


    waitThread

    public boolean waitThread(int timeout)
    Suspend execution of the current thread until the child process dies or the timeout hits. This function is not recommended for programs with a GUI.

    Parameters:
    timeout - timeout in seconds. -1 means wait indefinitely.
    Returns:
    true if the process exited, false if the timeout hit.

    waitThread

    public boolean waitThread()

    normalExit

    public boolean normalExit()
    Checks whether the process exited cleanly.

    Returns:
    true if the process has already finished and has exited "voluntarily", ie: it has not been killed by a signal.

    signalled

    public boolean signalled()
    Checks whether the process was killed by a signal.

    Returns:
    true if the process has already finished and has not exited "voluntarily", ie: it has been killed by a signal.

    coreDumped

    public boolean coreDumped()
    Checks whether a killed process dumped core.

    Returns:
    true if signalled() returns true and the process dumped core. Note that on systems that don't define the WCOREDUMP macro, the return value is always false.

    exitStatus

    public int exitStatus()
    Returns the exit status of the process.

    Returns:
    the exit status of the process. Note that this value is not valid if normalExit() returns false.

    exitSignal

    public int exitSignal()
    Returns the signal the process was killed by.

    Returns:
    the signal number that caused the process to exit. Note that this value is not valid if signalled() returns false.

    writeStdin

    public boolean writeStdin(java.lang.String buffer,
                              int buflen)
    Transmit data to the child process' stdin. This function may return false in the following cases:
  • The process is not currently running. This implies that you cannot use this function in Block mode.
  • Communication to stdin has not been requested in the start() call.
  • Transmission of data to the child process by a previous call to writeStdin() is still in progress.
  • Please note that the data is sent to the client asynchronously, so when this function returns, the data might not have been processed by the child process. That means that you must not free buffer or call writeStdin() again until either a wroteStdin() signal indicates that the data has been sent or a processExited() signal shows that the child process is no longer alive. If all the data has been sent to the client, the signal wroteStdin() will be emitted.

    Parameters:
    buffer - the buffer to write
    buflen - the length of the buffer
    Returns:
    false if an error has occurred

    closeStdin

    public boolean closeStdin()
    Shuts down the Stdin communication link. If no pty is used, this causes "EOF" to be indicated on the child's stdin file descriptor.

    Returns:
    false if no Stdin communication link exists (any more).

    closeStdout

    public boolean closeStdout()
    Shuts down the Stdout communication link. If no pty is used, any further attempts by the child to write to its stdout file descriptor will cause it to receive a SIGPIPE.

    Returns:
    false if no Stdout communication link exists (any more).

    closeStderr

    public boolean closeStderr()
    Shuts down the Stderr communication link. If no pty is used, any further attempts by the child to write to its stderr file descriptor will cause it to receive a SIGPIPE.

    Returns:
    false if no Stderr communication link exists (any more).

    closePty

    public boolean closePty()
    Deletes the optional utmp entry and closes the pty. Make sure to shut down any communication links that are using the pty before calling this function.

    Returns:
    false if the pty is not open (any more).

    closeAll

    public void closeAll()
    See Also:
    closeStdin(), @see, closeStdout(), @see, closeStderr(), @see, closePty()

    setRunPrivileged

    public void setRunPrivileged(boolean keepPrivileges)
    Controls whether the started process should drop any setuid/setgid privileges or whether it should keep them. Note that this function is mostly a dummy, as the KDE libraries currently refuse to run with setuid/setgid privileges. The default is false: drop privileges

    Parameters:
    keepPrivileges - true to keep the privileges

    runPrivileged

    public boolean runPrivileged()
    Returns whether the started process will drop any setuid/setgid privileges or whether it will keep them.

    Returns:
    true if the process runs privileged

    setEnvironment

    public void setEnvironment(java.lang.String name,
                               java.lang.String value)
    Adds the variable name to the process' environment. This function must be called before starting the process.

    Parameters:
    name - the name of the environment variable
    value - the new value for the environment variable

    setWorkingDirectory

    public void setWorkingDirectory(java.lang.String dir)
    Changes the current working directory (CWD) of the process to be started. This function must be called before starting the process.

    Parameters:
    dir - the new directory

    setUseShell

    public void setUseShell(boolean useShell,
                            java.lang.String shell)
    Specify whether to start the command via a shell or directly. The default is to start the command directly. If useShell is true shell will be used as shell, or if shell is empty, /bin/sh will be used. When using a shell, the caller should make sure that all filenames etc. are properly quoted when passed as argument.

    Parameters:
    useShell - true if the command should be started via a shell
    shell - the path to the shell that will execute the process, or 0 to use /bin/sh. Use getenv("SHELL") to use the user's default shell, but note that doing so is usually a bad idea for shell compatibility reasons.
    See Also:
    quote(java.lang.String)

    setUseShell

    public void setUseShell(boolean useShell)

    detach

    public void detach()
    Detaches KProcess from child process. All communication is closed. No exit notification is emitted any more for the child process. Deleting the KProcess will no longer kill the child process. Note that the current process remains the parent process of the child process.


    setPriority

    public boolean setPriority(int prio)
    Sets the scheduling priority of the process.

    Parameters:
    prio - the new priority in the range -20 (high) to 19 (low).
    Returns:
    false on error; see setpriority(2) for possible reasons.

    quote

    public static java.lang.String quote(java.lang.String arg)
    This function can be used to quote an argument string such that the shell processes it properly. This is e. g. necessary for user-provided file names which may contain spaces or quotes. It also prevents expansion of wild cards and environment variables.

    Parameters:
    arg - the argument to quote
    Returns:
    the quoted argument

    setupEnvironment

    protected void setupEnvironment()
    Sets up the environment according to the data passed via setEnvironment()


    setupCommunication

    protected int setupCommunication(int comm)
    This function is called from start() right before a fork() takes place. According to the comm parameter this function has to initialize the in, out and err data members of KProcess. This function should return 1 if setting the needed communication channels was successful. The default implementation is to create UNIX STREAM sockets for the communication, but you could reimplement this function to establish a TCP/IP communication for network communication, for example.


    commSetupDoneP

    protected int commSetupDoneP()
    Called right after a (successful) fork() on the parent side. This function will usually do some communications cleanup, like closing in[0], out[1] and out[1]. Furthermore, it must also create the QSocketNotifiers innot, outnot and errnot and connect their Qt signals to the respective KProcess slots. For a more detailed explanation, it is best to have a look at the default implementation in kprocess.cpp.


    commSetupDoneC

    protected int commSetupDoneC()
    Called right after a (successful) fork(), but before an exec() on the child process' side. It usually duplicates the in[0], out[1] and err[1] file handles to the respective standard I/O handles.


    processHasExited

    protected void processHasExited(int state)
    Immediately called after a successfully started process in NotifyOnExit mode has exited. This function normally calls commClose() and emits the processExited() signal.

    Parameters:
    state - the exit code of the process as returned by waitpid()

    commClose

    protected void commClose()
    Cleans up the communication links to the child after it has exited. This function should act upon the values of pid() and runs. See the kprocess.cpp source for details.
  • If pid() returns zero, the communication links should be closed only.
  • if pid() returns non-zero and runs is false, all data immediately available from the communication links should be processed before closing them.
  • if pid() returns non-zero and runs is true, the communication links should be monitored for data until the file handle returned by KProcessController.theKProcessController.notifierFd() becomes ready for reading - when it triggers, runs should be reset to false, and the function should be immediately left without closing anything.
  • The previous semantics of this function are forward-compatible, but should be avoided, as they are prone to race conditions and can cause KProcess (and thus the whole program) to lock up under certain circumstances. At the end the function closes the communication links in any case. Additionally
  • if runs is true, the communication links are monitored for data until all of them have returned EOF. Note that if any system function is interrupted (errno == EINTR) the polling loop should be aborted.
  • if runs is false, all data immediately available from the communication links is processed.
  • @short Cleans up the communication links to the child after it has exited.


    setBinaryExecutable

    protected void setBinaryExecutable(java.lang.String filename)
    Specify the actual executable that should be started (first argument to execve) Normally the the first argument is the executable but you can override that with this function.


    childOutput

    protected int childOutput(int fdno)
    Called by slotChildOutput() this function copies data arriving from the child process' stdout to the respective buffer and emits the signal receivedStdout().


    childError

    protected int childError(int fdno)
    Called by slotChildError() this function copies data arriving from the child process' stderr to the respective buffer and emits the signal receivedStderr().


    slotChildOutput

    protected void slotChildOutput(int fdno)
    This slot gets activated when data from the child's stdout arrives. It usually calls childOutput().

    Parameters:
    fdno - the file descriptor for the output

    slotChildError

    protected void slotChildError(int fdno)
    This slot gets activated when data from the child's stderr arrives. It usually calls childError().

    Parameters:
    fdno - the file descriptor for the output

    slotSendData

    protected void slotSendData(int dummy)
    Called when another bulk of data can be sent to the child's stdin. If there is no more data to be sent to stdin currently available, this function must disable the QSocketNotifier innot.

    Parameters:
    dummy - ignore this argument

    finalize

    protected void finalize()
                     throws java.lang.InternalError
    Deletes the wrapped C++ instance

    Overrides:
    finalize in class org.kde.qt.QObject
    Throws:
    java.lang.InternalError

    dispose

    public void dispose()
    Delete the wrapped C++ instance ahead of finalize()

    Overrides:
    dispose in class org.kde.qt.QObject

    isDisposed

    public boolean isDisposed()
    Has the wrapped C++ instance been deleted?

    Overrides:
    isDisposed in class org.kde.qt.QObject