Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inappropriate I/O control operation

my question is rather simple,. but can't resolve "Inappropriate I/O control operation" error which I'm receiving after execution of my Perl script.

#!C:/Perl/bin/perl.exe -w
use strict;

my $file = "D:/file.csv";
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
while (my $line = <$data>) {
    chomp $line; 
    my @fields = split "," , $line;
    print $fields[1]."\n";
}

any idea, what I'm doing wrong? I'm running this script on ActiveState perl on windows7

like image 622
taiko Avatar asked Feb 23 '14 13:02

taiko


1 Answers

My suspicion is that your script is printing the value of $! through an open && die $! or open or die $!; print $!;.

Here is a minimal script that reproduces the same issue on Windows:

C:\> perl -e "open my $fh, '<', 'file_that_opens' && die $!"
Inappropriate I/O control operation

And here is what happens on *nix:

$ perl -e 'open my $fh, "<", "file_that_opens" && die $!'
Inappropriate ioctl for device

This behavior is documented

According to perldoc perlvar, $! is only meaningful in the event of a failure. When open is called, it sets a value for $!, but the value is only useful if the open did not succeed:

... $! is meaningful only immediately after a failure:

if (open my $fh, "<", $filename) {
              # Here $! is meaningless.
    ...
}
else {        # ONLY here is $! meaningful.
    ...       # Already here $! might be meaningless.
}
# Since here we might have either success or failure,
# $! is meaningless.

Here, meaningless means that $! may be unrelated to the outcome of the open() operator.

like image 108
Zaid Avatar answered Sep 29 '22 15:09

Zaid