# process.child ## Function Starts the child process and saves the handle in the current Process object. Keep a `Process` handle for as long as the managed child needs to run. If it needs to outlive the function that starts it, return the handle and keep it in the caller. ## Syntax ```bt process(program).child() ``` ## Parameters No parameters. ## Return value | Type | Description | | ------ | ------ | | Process | Returns a Process object that shares the same child process handle. | ## Example ```bt fn start_worker(program, args) { return process(program).args(args).null_stdio().child() } let worker = if BT.OS == 'windows' { start_worker('cmd', ['/C', 'exit 0']) } else { start_worker('sh', ['-c', 'exit 0']) } let result = worker.wait() // Output: 0 print result ``` ## Notes - Cloned objects of the same Process share child process handles. - The stdout/stderr pipe is started by default, and can be read later through stdout_read, stdout_read_lines, stderr_read, and stderr_read_lines. - When stdin(text) is not called, child() will close the child process stdin and will not inherit the parent process stdin, preventing desktop apps or background services from inheriting invalid input handles. - The console child process window is hidden by default under Windows, and a black console window will not pop up when starting the console program in the desktop app. - Call `null_stdio()` before `child()` when the worker needs no input or output. This avoids allocating script-side pipe readers. `inherit_stdio()` also disables script-side pipe readers and connects the child to the parent console. - If stdin(text) is called in advance, child() will write the text and close the stdin pipe to avoid the child process waiting for input for a long time. - Releasing the last handle terminates a still-running managed child. A discarded temporary can therefore stop the child as soon as the expression finishes. On Windows, cleanup attempts to terminate the child process tree. - For synchronous execution, use [process.status](/en/docs/process/status) for the exit code or [process.output](/en/docs/process/output) to capture output.