Dpkg::IPC — helper functions for IPC
| Use Case | Command | Description |
|---|---|---|
| Execute a program | spawn(%opts) | Creates a child process and executes a program. |
| Wait for a process | wait_child($pid, %opts) | Waits for a child process to finish. |
| Redirect stdin/stdout/stderr | from_*, to_*, error_to_* | Redirect I/O to files, handles, pipes, or strings. |
| Set environment variables | env | Populate %ENV in the child process. |
| Delete environment variables | delete_env | Remove environment variables in the child process. |
| Set signal handlers | sig | Populate %SIG in the child process. |
| Delete signal handlers | delete_sig | Reset signals to default dispositions. |
| Change directory | chdir | Child process changes directory before exec. |
| Wait with timeout | timeout | Kill the child process if it exceeds the time limit. |
Dpkg::IPC offers helper functions to allow you to execute other programs in an easy, yet flexible way, while hiding all the gory details of IPC (Inter-Process Communication) from you.
$pid = spawn(%opts)
Creates a child process and executes another program in it. The arguments are interpreted as a hash of options, specifying how to handle the in and output of the program to execute. Returns the pid of the child process (unless the wait_child option was given).
Any error will cause the function to exit with one of the Dpkg::ErrorHandling functions.
Options:
exec — Mandatory. Can be either a scalar (program name) or an array reference (program name + arguments). The program will never be executed via the shell, so you can't specify additional arguments in the scalar string or use shell facilities like globbing.from_file, to_file, error_to_file — Filename as scalar. Standard input/output/error of the child process will be redirected to the file specified.from_handle, to_handle, error_to_handle — Filehandle. Standard input/output/error of the child process will be dup'ed from the handle.from_pipe, to_pipe, error_to_pipe — Scalar reference or IO::Handle object. A pipe will be opened. The reading end (to_pipe and error_to_pipe) or writing end (from_pipe) will be returned in the referenced scalar. Standard input/output/error of the child process will be dup'ed to the other ends of the pipes.from_string, to_string, error_to_string — Scalar reference. Standard input/output/error redirected to the string. Note that it wouldn't be strictly necessary to use a scalar reference for from_string, as the string is not modified. This was chosen for symmetry with to_string and error_to_string. to_string and error_to_string imply the wait_child option.wait_child — Scalar. If true, wait_child() will be called before returning. The return value of spawn() will be a true value, not the pid.nocheck — Scalar. Option of the wait_child() call.timeout — Scalar. Option of the wait_child() call.chdir — Scalar. The child process will chdir to the indicated directory before calling exec.env — Hash reference. The child process will populate %ENV with the items of the hash before calling exec. This allows exporting environment variables.delete_env — Array reference. The child process will remove all environment variables listed in the array before calling exec.sig — Hash reference. The child process will populate %SIG with the items of the hash before calling exec. This allows setting signal dispositions.delete_sig — Array reference. The child process will reset all signals listed in the array to their default dispositions before calling exec.wait_child($pid, %opts)
Takes as first argument the pid of the process to wait for. Remaining arguments are taken as a hash of options. Returns nothing. Fails if the child has been ended by a signal or if it exited non-zero.
Options:
cmdline — String to identify the child process in error messages. Defaults to "child process".nocheck — If true do not check the return status of the child (and thus do not fail if it has been killed or if it exited with a non-zero return code).timeout — Set a maximum time to wait for the process, after that kill the process and fail with an error message.Change options: wait_child() now kills the process when reaching the timeout.
New options: spawn() now accepts sig and delete_sig.
Mark the module as public.
1.21.1 2025-09-09 Dpkg::IPC(3perl)
Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-27 02:13 @216.73.217.85
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)