Subject: | spawn() returns 0 if standard input is not a TTY |
Documentation reads:
=head2 spawn(@argv)
Fork a new subprocess, with stdin/stdout/stderr tied to the pty.
The argument list is passed directly to C<exec()>.
Returns true on success, false on failure.
That's true if perl's standard input is a TTY:
$ perl -Ilib -e 'use IO::Pty::Easy; my $pty=IO::Pty::Easy->new; my $r=$pty->spawn(q{true}); warn $r; $pty->close'
1 at -e line 1.
But if the standard input is not a TTY, it returns false despite everything works:
$ perl -Ilib -e 'use IO::Pty::Easy; my $pty=IO::Pty::Easy->new; my $r=$pty->spawn(q{true}); warn $r; $pty->close' </dev/null
0 at -e line 1.
The reason is new() checks for TTY:
$handle_pty_size = 0 unless POSIX::isatty(*STDIN);
and then spawn() finishes with:
if ($self->handle_pty_size) {
my $weakself = weaken($self);
$SIG{WINCH} = sub {
return unless $weakself;
$weakself->slave->clone_winsize_from(\*STDIN);
kill WINCH => $weakself->pid if $weakself->is_active;
};
${*{$self}}{io_pty_easy_did_handle_pty_size} = 1;
}
So the return value is a value of the last executed command that is an assignment of 1.
I believe the spawn() croaks on any error, therefore documentation is wrong and the return value is meaning less. Am I right?