NAME
Sys::Cmd::Process - process interaction object for Sys::Cmd
VERSION
v0.986.3 (2025-12-11)
SYNOPSIS
use Sys::Cmd qw[spawn];
my $proc = spawn(
'/usr/bin/cat', '--number',
{
dir => '/',
input => "x\ny\nz\n",
}
);
while ( my $line = $proc->stdout->getline ) {
print $line;
}
my @errors = $proc->stderr->getlines;
$proc->wait_child() or warn $proc->status;
# Or manually read process termination information
$proc->exit(); # exit status
$proc->signal(); # signal
$proc->core(); # core dumped? (boolean)
DESCRIPTION
The Sys::Cmd::Process class is used by Sys::Cmd to represent a running process. It holds Input/Output file handles and a few methods for finalising the process and obtaining exit information.
Process objects come with the following read-only attributes:
- cmdline() -> @list | $string
-
In array context returns a list of the command and its arguments. In scalar context returns a string of the command and its arguments joined together by spaces.
- pid() -> $int
-
The command's process ID.
- stdin() -> IO::Handle
-
The command's STDIN file handle, based on IO::Handle so you can call print() etc methods on it. Autoflush is automatically enabled on this handle.
- stdout() -> IO::Handle
-
The command's STDOUT file handle, based on IO::Handle so you can call getline() etc methods on it.
- stderr() -> IO::Handle
-
The command's STDERR file handle, based on IO::Handle so you can call getline() etc methods on it.
When no more interaction with the process is required, the following methods are used for cleanup:
- close()
-
Close the remaining open filehandles to the child process.
- wait_child() -> $bool
-
Wait for the child process to finish using waitpid and collect the exit status. Returns true if the child terminated normally.
After wait_child has been called the following attributes are also valid:
- core() -> $bool
-
A boolean indicating if the process core was dumped.
- exit() -> $int
-
The command's exit value.
- signal() -> $int
-
The signal number (if any) that terminated the command.
- status() -> $str
-
A description of the process state. Sys::Cmd::Process sets it to a string starting with one of the following:
Running - set at creation time
Terminated - normal process exit
Non-zero exit - unusual process exit
Killed - termination via signal
This attribute can be set by the caller if desired, but note that
wait_child()overwrites it.
AUTHOR
Mark Lawrence <mark@rekudos.net>
COPYRIGHT AND LICENSE
Copyright 2011-2025 Mark Lawrence <mark@rekudos.net>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.