Inappropriate ioctl for device

13,142

An "ioctl" is a POSIX operation to send a control command to a device ("I/O control"). The "Inappropriate ioctl" error means that the program sent an ioctl to a device that wasn't correct in some way. The question is what ioctls this spotify program may be using that are dependent on how it's run.

When you run the spotify program from the command line, it has a TTY. When your PHP code launches the program, it doesn't have a TTY. It's probably sending an ioctl to its standard output for some reason, expecting standard output to be a tty. My guess is that it's using an ioctl to get the terminal width so that it can display that progress bar graphic.

There are two ways to fix this. You could check the documentation for this spotify program to see if it has a noninteractive mode or batch mode or quiet mode that disables printing the progress bar. That might avoid performing the ioctl that's failing.

The other fix is to have PHP request a pty (pseudo-TTY) for the ssh session. I'm not a PHP coder, but this page appears to describe the Net_SSH2 API, and it lists a function to enable requesting a PTY for calls to exec().

Share:
13,142
Toby Mellor
Author by

Toby Mellor

Updated on June 17, 2022

Comments

  • Toby Mellor
    Toby Mellor almost 2 years

    I'm trying to execute SSH commands through a PHP application.

    Through the PHP application, I type "./SSDownload.sh". Through my terminal SSH, I type "./SSDownload.sh".

    SSDownload.sh contains:

    cd /var/www/html/dev/media/mp3/$1
    spotify-to-mp3 songs.txt
    

    Through my terminal SSH, I get this response:

    Resolving "fancy iggy azalea"
    Searching "fancy iggy azalea" on Grooveshark
    "Iggy Azalea - Fancy (feat. Charli XCX)" will be downloaded
    
    Downloading tracks...
    [1/1] Iggy Azalea - Fancy (feat. Charli  100% [==================================] Time: 00:00:01
    Download complete
    

    The file downloads successfully, and places the files in the correct directory.

    I tried the same with PHP using the following code:

    include('Net/SSH2.php');
    $ssh = new Net_SSH2('iphere');
    if (!$ssh->login('root', 'password')) {
    exit('Login Failed');
    }
    
    echo "1 : " . $ssh->exec('./SSDownload.sh ' . $_GET['player']) . "<br />";
    

    Output:

    Resolving "fancy iggy azalea" Searching "fancy iggy azalea" on Grooveshark "Iggy Azalea - Fancy (feat. Charli XCX)" will be downloaded Downloading tracks... [0;31;49mInappropriate ioctl for device[0m [0;32;49mDownload complete[0m
    

    The file does not download successfully, and does not place the files in the correct directory.

    I'd like to bring your attention to "Inappropriate ioctl for device", whatever it means.

    Why are the responses different? How can I go about fixing it?