It's quite possible the
Inappropriate ioctl for device is a red herring.
$! will only be set if a call to the OS fails. Since a program run by
system returning a nonzero exit status isn't considered a failed OS call,
$! may contain gibberish. You may find more useful information by looking at
$?, and/or any error output from the program you're running.