Process Service

The Process service allows you to start processes, track their output, and so on.

Available Operations

Constructor


  Process()

Allocates and returns a new Process object.

close


  close(): void

Frees the resources associated with the process. It is recommended to always call this function as soon as you are finished with the process.

closeWriteChannel


  closeWriteChannel(): void

Schedules the stdin channel of process to be closed. The channel will close once all data has been written to the process. After calling this function, any attempts to write to the process will do nothing. See QProcess::closeWriteChannel() for more details.

exec


  exec(filePath: string, arguments: string[], throwOnError: boolean): number

Executes the program at filePath with the given argument list and blocks until the process is finished. If an error occurs (for example, there is no executable file at filePath) and throwOnError is true, then a JavaScript exception will be thrown. Otherwise (the default), -1 will be returned in case of an error. The normal return code is the exit code of the process.

exitCode


  exitCode(): number

Returns the exit code of the process. This is needed for retrieving the exit code from processes started via start(), rather than exec().

getEnv


  getEnv(varName: string): string

Returns the value of the variable varName in the process' environment.

kill


  kill(): void

Kills the process, causing it to exit immediately.

readLine


  readLine(): string

Reads and returns one line of text from the process output, without the newline character(s).

readStdErr


  readStdErr(): string

Reads and returns all data from the process' standard error channel.

readStdOut


  readStdOut(): string

Reads and returns all data from the process' standard output channel.

setCodec


  setCodec(codec)

Sets the text codec to codec. The codec is used for reading and writing from and to the process, respectively. The supported codecs are the same as for QTextCodec, for example: "UTF-8", "UTF-16", and "ISO 8859-1".

setEnv


  setEnv(varName: string, varValue: string): string

Sets the value of variable varName to varValue in the process environment. This only has an effect if called before the process is started.

setWorkingDirectory


  setWorkingDirectory(path: string): void

Sets the directory the process will be started in. This only has an effect if called before the process is started.

start


  start(filePath: string, arguments: string[]): boolean

Starts the program at filePath with the given list of arguments. Returns true if the process could be started and false otherwise.

Note: This call returns right after starting the process and should be used only if you need to interact with the process while it is running. Most of the time, you want to use exec() instead.

terminate


  terminate(): void

Tries to terminate the process. This is not guaranteed to make the process exit immediately; if you need that, use kill().

waitForFinished


  waitForFinished(timeout: number): boolean

Blocks until the process has finished or timeout milliseconds have passed (default is 30000). Returns true if the process has finished and false if the operation has timed out. Calling this function only makes sense for processes started via start() (as opposed to exec()).

workingDirectory


  workingDirectory(): string

Returns the directory the process will be started in.

write


  write(data: string): void

Writes data into the process' input channel.

writeLine


  writeLine(data: string): void

Writes data, followed by the newline character(s), into the process' input channel.