I am trying to call the scanimage command (from the SANE tool) from inside cygwin though I think that my problem is one of general escaping so maybe what I am calling doesn't matter. Anyway...

The fly in the ointment is that I need to call said command from a windows command prompt (so calling bash.exe) and I cannot work out how to pass the arguments correctly. Here is an example:

If I run up a cygwin terminal I can run this command and it works nicely:

 scanimage -d 'epson2:libusb:bus-0:\\.\libusb0-0001--0x04b8-0x012c' -y 20 --format tiff > out.tiff

Great, but when I bring up a regular command prompt and put in this (the original command but inside the -c "" bit):

"c:\cygwin\bin\bash.exe" --login -c "scanimage -d 'epson2:libusb:bus-0:\\.\libusb0-0001--0x04b8-0x012c' -y 20 --format tiff > out.tiff"

I get back this error:

scanimage: open of device epson2:libusb:bus-0:.\libusb0-0001--0x04b8-0x012c failed: Invalid argument

This seems really odd to me, since how it is describing the argument in the error looks like it has got the correct value (if it hadn't passed it correctly I would expect it to be '' or something, but maybe that's just me).

Incidentally, if I ditch the -d argument and do this

"c:\cygwin\bin\bash.exe" --login -c "scanimage -y 20 --format tiff > out.tiff"

all is good - except of course that if I connect another scanner I have a 50/50 chance of it scanning on the wrong one, so omitting the argument is not really an option.

I thought of one way to do it: create a bsh file with the command in and then just launch that file from bash.exe ("c:\cygwin\bin\bash.exe" --login scan.bsh where scan.bsh contains the aforementioned command) but that seems, well, a bit icky.

So my question is, therefore, how can I construct the command line for bash.exe such that, in this case, the device argument is properly passed and the scanner scans my stuff?


You'll need to escape every \ in the command you're passing with an extra \.

"c:\cygwin\bin\bash.exe" --login -c "scanimage -d 'epson2:libusb:bus-0:\\\\.\\libusb0-0001--0x04b8-0x012c' -y 20 --format tiff > out.tiff"
  • awesome thank you! I didn't notice that the \ had been lost in the error message. – kmp Mar 7 '13 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.