in reply to Re: capturing syswrite failures
in thread capturing syswrite failures

In case $data is empty,

unless ( syswrite( $pc, $data ) == length $data ) { # ... }

Or maybe just

unless ( defined syswrite( $pc, $data ) ) { # ... }

(Should it be considered an error if syswrite writes some number of bytes different from the length of the string you give it?)

Replies are listed 'Best First'.
Re^3: capturing syswrite failures
by ikegami (Patriarch) on Mar 01, 2007 at 19:39 UTC

    Should it be considered an error if syswrite writes some number of bytes different from the length of the string you give it?

    No.

    my $to_write = length($data); my $offset = 0; while ($to_write > 0) { my $written = syswrite($fh, $data, $to_write, $offset); die("Unable to write to ...: $!\n") if not defined $written; $to_write -= $written; $offset += $written; }