which indicates the number of characters or bytesconsumed from data. Any data not consumed will be included again thenext time the handler is called. If a process.stream() handler is set up, [options]) Spawns a process on the system. The args should be an array starting with the executable andcontaining all the arguments to pass on the command line. If args isa string then it is interpreted as an executable name. The optionaloptions argument is a javascript plain object and can contain any ofthe following fields: "binary" If set to true then handle the input and output of the process asarrays of binary bytes. "directory" The directory to spawn the process in. "err" Controls where the standard error is sent. By default it is logged tothe journal. If set to "out" it is included in with the outputdata. If set to "ignore" then the error output is discarded. Ifset to "message", unless the process was opened in binary mode, [options]) Run a shell script on the system. This function a Bourne shell scriptprocess. The full text of the /bin/sh shell script should be passedin as the first argument. The args can be an array of arguments, then any standard output data consumed by the handler will notbe included in the data argument. If the process was spawned with the "err" option set to"message" then the second argument will contain the standard erroroutput of the process. process.catch() process.catch((exception[, cockpit.js: Spawning Processes This is the API for spawning a process and receiving its output, it willbe available in the data argument. Otherwise this argument will beundefined. process.stream() process.stream(data = { ... }) This sets up a handler to be called when the process has standardoutput. The handler will be called multiple times. The handler will becalled regardless of whether the process ends up exiting successfully ornot. Only one handler may be registered at a time. Registering an additionalhandler replaces the previous one. The handler receives either stringdata or an array of binary bytes as its argument. A stream handlermay return a number, which are passed to the script as $1, in which casethe data is an array of bytes. If a process.stream() handler isset up,$2 and so on. Shebang options are not used or respected. The options is an optional javascript plain object and can includeany of the fields listed for the function. The spawned process is athat will complete if the script exits successfully, then it will be returned as the error message.When the "pty" field is set, or fail if theresa problem. Some additional methods besides the standard promise methodsare documented below. The standard output of the process is made available via the spawnedprocess object. Any non-UTF8 output from the process will be coercedinto textual form. It is highly recommended that only textual output beproduced by the command. The standard error is logged to the journal bydefault. process.then() process.then((data[, as wellas exit codes. cockpit.spawn() process = cockpit.spawn(args,fall back to an unprivileged process. The spawned process is athat will complete if the process exits successfully。
but if that fails, notincluding the executable, and send/receive terminalinput and output. "batch" Batch data coming from the process in blocks of at least this size.This is not a guarantee. After a short timeout the data will be senteven if the data doesnt match the batch size. Defaults to zero. "latency" The timeout for flushing any cached data in milliseconds. "superuser" Set to "require" to spawn the process as root instead of thelogged in user. If the currently logged in user is not permitted tobecome root (eg: via pkexec) then the client will immediatelybe with a "access-denied"problem code.+Set to "try" to try to run the process as root。
message]) = { ... }) This is a standardmethod. It sets up a handler to be called when the process finishessuccessfully. The data argument contains the standard output of the process. If ita string。
or fail if theresa problem. Some additional methods besides the standard promise methodsare documented below. The standard output of the process is made available via the spawnedprocess object. Any non-UTF8 output from the process will be coercedinto textual form. It is highly recommended that only textual output beproduced by the command. The standard error is logged to the journal. cockpit.script() process = cockpit.script(script, then the process.then()handlers will only get any remaining data not consumed by the streamhandler. process.input() process.input(data,terminates or exits. The exception object passed to the handler can have the followingfields: message A message describing the exception. If the process was spawned withthe "err" option set to "message" then the second argumentwill contain the standard error output of the process. problem A string when a problem occurredstarting or communicating with the process. This is null if theprocess exited or was terminated. exit_status The numeric exit status of the process. This is null if theprocess did not exit. exit_signal A string representing a unix signal that caused the process toterminate. This is null if the process did not terminate becauseof a signal. If the process actually ran and produced output before failing, [args], [stream]) This method writes data to the standard input of the process. Ifdata is null or undefined it is not sent. The datashould be a string or an array of bytes if the process was opened inbinary mode. If stream is set to true then this function may be called againwith further input. Otherwise the standard input of the process isclosed. process.close() process.close([problem]) Close the process by closing its standard input and output. Ifproblem is specified it should be a standard string. In this case the processwill be terminated with a signal. , this field has no effect. "environ" An optional array that contains strings to be used as additionalenvironment variables for the new process. These are "NAME=VALUE"strings. "pty" Launch the process in its own PTY terminal, data]) = { ... }) This is a standardmethod. It sets up a handler to be called when the process fails,。
