in reply to Character encoding in console in Windows

using binmode on STDIN doesn't change how the console (cmd.exe) behaves. Unless you've configured cmd.exe to supply utf, you won't get utf ... also perl on win32 needs something like Win32::Unicode for unicode filenames
  • Comment on Re: Character encoding in console in Windows

Replies are listed 'Best First'.
Re^2: Character encoding in console in Windows
by elef (Friar) on Sep 11, 2010 at 19:01 UTC
    Thank you for your answer.

    I was hoping this problem was not inherent in CMD.exe...
    Are you saying that there is no way for a user to drag and drop a file with a non-ASCII name into the console window and have the perl script open that file? Or would installing Win32::Unicode fix this automagically?

    "Fixing" cmd.exe is not an option as this script is not intended for my own use. It's an open source script that will mostly be used by computer illiterate people.

    It's not really clear to me how the module you linked works... would I need to change my filehandle open and print commands or would it do its thing in the background without the need to change the script itself?

      I was hoping this problem was not inherent in CMD.exe... Are you saying that there is no way for a user to drag and drop a file with a non-ASCII name into the console window and have the perl script open that file?

      To my knowledge, you've never been able to drag & drop a file into a console window and have anything happen.

      It not a perl "problem". Not a cmd.exe "problem". Just something that has never been designed in. Where did you get the idea it was possible?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Of course it's possible, you are probably misunderstanding me. When you drop in a file, the console displays its path, and then the script can take that as input.

        So what my code does is:

        1. tell the user to drag and drop a file in the console, wait for input via STDIN
        2. user drags & drops file from file manager into console, the full filepath appears in the console, user presses enter
        3. the script stores the string with the filepath in a variable, parses it, opens the file, magic happens

        Pretty much all OSes have this functionality apart from Windows Vista (XP and Win7 have it, Vista is the only one that doesn't).

        This is pretty much the default method for cd'ing into a directory for most people... you type "cd ", drag and drop a folder and press enter... it eliminates a hell of a lot of typing.
        It works fine in my script in most scenarios, but not with accented characters on Windows.

        BTW the same will often work with URLs, depending on what browser you have and which bit you're grabbing. If you grab a photo from an open webpage, the URL of the image should appear in the console, and you can often drag & drop favicons or links etc.

        Try it, what happens is the filepath get pasted into the current line