I have encountered a similar issue, however while using Arduino-CLI.
Please find below a short summary of the issue quoted in the subject and my observations about the same.
Issue/Problem Statement : The arduino-cli “upload” command throws the below error while being used to deploy a sketch(code) onto two specific AVR targets namely Arduino Mega 2560 and Arduino Mega ADK when a wrong/invalid/non-existing COM port is specified:
avrdude: ser_open(): can't open device "/dev/ttyACM0": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
Where is the issue observed : The above issue is seen only on the Linux and MAC platforms and not on Windows. On Windows, the expected error is provided by the command as seen in the attached screenshot.
Step to reproduce the issue :
For Mega 2560:
<path to aCLI folder>/arduino-cli upload --fqbn arduino:avr:mega --discovery-timeout <duration>s --port /dev/ttyACM0 "<path to a compiled sample sketch>" --config-file “<path to the yaml configuration file within the aCLI folder>”
For Mega ADK:
<path to aCLI folder>/arduino-cli upload --fqbn arduino:avr:megaADK --discovery-timeout <duration>s --port /dev/ttyACM0 "<path to a compiled sample sketch>" --config-file “<path to the yaml configuration file within the aCLI folder>”
Observation about the issue : Upon referring the error log given by the command for another AVR target ie., the Uno board as shown below, it is observed to be working as expected even on Linux and MAC
avrdude: ser_open(): can't open device "/dev/ttyACM0": No such file or directory
Failed uploading: uploading error: exit status 1
Attempts of trying to use the --discovery-timeout parameter as an additional input to the upload command as suggested here, did not prove to be useful since it was not being regarded by the command.
Moreover, the command seems to be stuck for an indefinite period of time without fetching the exit status.