I'm running windows cmd script from windows console and redirecting output to a file by mycommand.cmd > 'filename ' 2>&1 the problem is, when I'm trying to read that file using less under cygwin, it says that file may be a binary and then can't detect encoding. I can open and see file correctly if I open it through, say, notepad++, it shows that file has USC-2 (BE) encoding. Is there a way to make less to understand file and display it correctly?


If the output is expected to be mostly ASCII, you can just delete the NULs with

tr -d '\0'

You could probably try to see if $LANG can be set to an UTF-16 locale, but I'm not really sure and I don't have a cygwin install at hand to try it; otherwise you can use iconv(1) to do the conversion, set $LANG to some sane value (ie an utf8 locale) and enjoy.

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.