Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Components
gb
gb.args
gb.cairo
gb.chart
gb.clipper
gb.complex
gb.compress
gb.crypt
gb.data
gb.db
gb.db.form
gb.db.mysql
gb.db.odbc
gb.db.postgresql
gb.db.sqlite2
gb.db.sqlite3
gb.dbus
gb.dbus.trayicon
gb.debug
gb.desktop
gb.desktop.gnome.keyring
gb.desktop.x11
gb.eval
gb.eval.highlight
gb.form
gb.form.dialog
gb.form.editor
gb.form.htmlview
gb.form.mdi
gb.form.print
gb.form.stock
gb.form.terminal
gb.gmp
gb.gsl
gb.gtk
gb.gtk.opengl
gb.gtk3
gb.gtk3.opengl
gb.gtk3.webview
gb.gui
gb.gui.opengl
gb.gui.qt
gb.gui.qt.ext
gb.gui.qt.opengl
gb.gui.qt.webkit
gb.gui.trayicon
gb.gui.webview
gb.hash
gb.highlight
gb.image
gb.image.effect
gb.image.imlib
gb.image.io
gb.inotify
gb.jit
gb.libxml
gb.logging
gb.map
gb.markdown
gb.media
gb.media.form
gb.memcached
gb.mime
gb.mongodb
gb.mysql
gb.ncurses
gb.net
gb.net.curl
gb.net.pop3
gb.net.smtp
gb.openal
gb.opengl
gb.opengl.glsl
gb.opengl.glu
gb.opengl.sge
gb.openssl
gb.option
gb.pcre
gb.pdf
gb.poppler
gb.qt4
gb.qt4.ext
gb.qt4.opengl
gb.qt4.webkit
gb.qt4.webview
gb.qt5
gb.qt5.ext
gb.qt5.opengl
gb.qt5.webkit
gb.qt5.webview
gb.qt6
gb.qt6.ext
gb.qt6.opengl
gb.qt6.webview
gb.report
gb.report2
gb.scanner
gb.sdl
gb.sdl.sound
gb.sdl2
gb.sdl2.audio
gb.settings
gb.signal
gb.term
gb.test
gb.util
Class
ClassStat
CsvFile
Date
File
Process
Expect
Prompt
Shell
String
gb.util.web
gb.v4l
gb.vb
gb.web
gb.web.feed
gb.web.form
gb.web.gui
gb.xml
gb.xml.html
gb.xml.rpc
gb.xml.xslt
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Process (gb.util)

Since 3.15

This class is used for managing processes launched by the EXEC or SHELL instructions.

The gb.util component overrides it to allow to detect prompts emitted by the process on its standard output, and answer them accordingly, through the Expect method and the Prompt event.

This class reimplements Process in gb.

This class is creatable.

Inherited constants
Crashed   Constant used by the State property to indicate a crashed process.
Running   Constant used by the State property to indicate a running process.
Signaled   A synonymous for the Crashed constant.
Stopped   Constant used by the State property to indicate a stopped process.

Inherited static properties
LastState   Returns the state of the last terminated process.
LastValue   Returns the return value of the last terminated process.

Inherited properties
Blocking   Returns or sets if the stream is blocking.
ByteOrder   Returns or sets the byte order used to read or write binary data to the stream.
EndOfFile   This property signals whether the last use of LINE INPUT reached the end of file, instead of reading a full line with an end-of-line character.
EndOfLine   Return or set the newline separator used by this stream.
Eof   Return if a stream reached its end.
Handle   Returns the process identifier (a.k.a "pid") of the process object.
Id   A synonymous for Handle.
Ignore   Return or set if the process is ignored.
IsTerm   Return if a stream is associated with a terminal.
Lines   Returns a virtual object that allows you to enumerate a stream line by line.
NoShare  
NullTerminatedString   Return or set if strings are null-terminated when they are serialized.
State   Returns the current state of the process object:
Tag   Returns or sets the tag associated with the stream.
Term   Return a virtual object that allows to manage the terminal associated with the stream.
Value   Returns the value returned by the process when it exited, or the number of the emitted signal if it crashed.

Methods
Expect   Tell which answer must be sent when a specific prompt is emitted by the process on its standard input.

Inherited methods
Begin   Start to buffer data written to the stream, so that everything will be sent when the Send method is called.
Close   Closes the stream.
CloseInput   Closes the process input stream.
Drop   Drop the data that has been buffered since the last call to the Begin method.
Kill   Kills the process immediately.
ReadLine   Read a line of text from the stream, like the LINE INPUT instruction.
Send   Send all the data, in one shot, since the last call to Begin.
Signal   Sends a user signal to the process.
Wait   Waits for the end of the process, like the WAIT option in SHELL and EXEC instructions.
Watch   Start or stop watching the stream file descriptor for reading or writing, after it has been opened.

Events
Prompt   This event is raised when a prompt specified by the Expect method has been detected on the standard output of the process.

Inherited events
Error   Raised when there is data to be read on the standard error output of the process.
Kill   Raised when the process has terminated, normally or abnormally.
Read   Raised when there is data to be read from the standard output of the process.

Example

Here is how to easily pilot the scp utility with the Expect method:

Dim hProcess As Process
Dim sPassword As String = "BigSecret"
  
hProcess = Shell "scp /all/that/stuff/* login@server:~/here" For Input Output As "Process"
' Handle the message emitted when the server is unknown
hProcess.Expect("(yes/no*)?", "yes")
' Any emitted string ending with a colon is supposed to be the password prompt
hProcess.Expect(":", sPassword)
' Wait for the process to terminate
hProcess.Wait