process process library

process process library

process process library

Function

process(program) Creates a command builder that supports parameters, environment variables, working directory, stdio configuration, synchronous execution and subprocess handle operations.

API List

APIDescription
process.argAppend a command line argument.
process.argsAppend command line parameters in batches.
process.envSet a child process environment variable.
process.envsSet child process environment variables in batches.
process.current_dirSet the working directory of the child process.
process.stdinSet the text to be written to the standard input of the child process.
process.inherit_stdioLet the child process inherit the current process stdio.
process.null_stdioDiscard child process stdio.
process.window_hiddenHide the console child process window under Windows.
process.pipe_limitSet the stdout/stderr unread buffer limit of the current Process object.
process.env_clearClear the inherited environment variables before starting the child process.
process.env_removeRemoves a key from a configured environment variable.
process.get_argsRead the configured parameter array of the current builder.
process.get_current_dirRead the current builder working directory configuration.
process.get_envsRead the current builder environment variable configuration.
process.get_programRead the current builder program path.
process.statusExecute the command synchronously and return the exit code.
process.outputExecute the command synchronously and return the output object.
process.childStart the child process and save the handle in the current Process object.
process.pidRead the PID of the started child process.
process.killKill the started child process.
process.suspendSuspend the started child process and its child process tree under Windows.
process.resumeResume a suspended child process and its child process tree under Windows.
process.waitWait for the started child process to exit.
process.try_waitNon-blocking check whether the started child process has exited.
process.stdoutRead the started subprocess stdout pipe status.
process.stdout_readRead the currently available text of stdout of a started child process.
process.stdout_read_linesRead the currently available text of the started subprocess stdout line by line.
process.stderr_readRead the currently available text of stderr of a started subprocess.
process.stderr_read_linesRead the currently available text of a started subprocess stderr line by line.
process.child_runningDetermine whether the current Process object saves the child process handle.

Examples

Notes

  • The example uses Windows cmd as an example; Linux/macOS can use sh -c.
  • status, output, and wait will block the current process and should be used with caution in resident services.
  • Reject status, output, child, wait in the Web request context to avoid synchronously waiting for external processes or forking long-term child processes; for complete rules, see: Web blocking API policy .
  • The child process will inherit the BT runtime environment variable overlay; if the current Process object sets a variable with the same name through env/envs, the explicit configuration of the Process object shall prevail.
- The default non-inherit_stdio() scenario does not inherit the parent process stdin; the child process receives a closed stdin when stdin(text) is not called.
  • The default non-inherit_stdio() scenario under Windows will hide the console child process window; call inherit_stdio() when explicit interaction with the console is required.
  • child() opens the stdout/stderr pipe by default; inherit_stdio() or null_stdio() will turn off the script-side pipe reading capability.
  • Pipe reading uses background threads and bounded unread buffers. The default BT_PROCESS_PIPE_LIMIT is 1048576 bytes, BT_PROCESS_PIPE_READ_CHUNK is 8192 bytes, and BT_PROCESS_PIPE_TIMEOUT_MS is 100 milliseconds; a single Process can be overridden by pipe_limit(bytes).
  • Exceeding BT_PROCESS_PIPE_LIMIT or pipe_limit(bytes) will return a runtime error; return empty when the subprocess is not started, there is no corresponding pipe, there is no data within the timeout, or the pipe has been read.
  • When the Process object is finally released, it will terminate the still running managed sub-process; under Windows, kill() and release cleanup will try to recursively terminate the sub-process tree.
  • suspend()/resume() is for Windows desktop batch processing scenarios, controlling the sub-process tree through thread-level suspension and resumption; Linux/macOS is not supported yet.