Sending accented characters to Clipboard from a batch file

1

I've been trying to find a solution to this, but I wrote a basic program to automatically produce an "outage" report more or less, that I need copied into the clipboard so that I can paste it into a mainframe system. It needs to be in English and French, but the French accents are not copying properly... Is there anyway around this - to include the variables?

The output will basically be this le système ne (clipped out the rest).

Any assistance would be greatly appreciated.

This is that I have so far:

if "%SRSST%"=="n" (
    (
    echo                   ***  IMSNEWS ***
    echo.
    echo On Sunday, %DATEME% %DT%%DATEST% %DATEYR%, There will be no
    echo system outage.
) | Clip )else (
            echo                   ***  IMSNEWS ***
            echo.
            echo On Sunday, %DATEME% %DT%%DATEST% %DATEYR%, the system will not
            echo be available between %SRSST% - %SRSET% for regular
            echo weekly maintenance.
        ) | Clip
timeout /t 5
if "%SRSST%"=="n" (
    (
    echo                  ***  NOUVELLES ***
    echo.
    echo Le dimanche %DT% %DATEME%, %DATEYR%,  Il n'y aura pas
    echo d'interruption du système 
) | Clip )else (
            echo                  ***  NOUVELLES ***
            echo.
            echo Le dimanche %DT% %DATEME%, %DATEYR%, le système ne
            echo sera pas disponible entre %SRSST% - %SRSET% pour la
            echo maintenance hebdomadaire.
        ) | Clip

goto Menu

Bob G

Posted 2016-04-29T18:14:41.317

Reputation: 11

"and the French accents are copying properly" If they're copying properly, then what's the problem exactly? Or was that a typo? – Ƭᴇcʜιᴇ007 – 2016-04-29T18:24:44.273

They are not copying properly at all > it's showing syst├¿me ne instead of système - as an example (in notepad) – Bob G – 2016-04-29T18:25:40.137

Seems to work fine here... Perhaps the target (the "mainframe system") you're pasting into is the problem... If you paste what it puts onto the clipboard into Notepad, does it display properly? – Ƭᴇcʜιᴇ007 – 2016-04-29T18:26:32.203

Sorry - just to be clear, when the output is pasted into notepad (or any other system) the character "è" looks like "├¿" – Bob G – 2016-04-29T18:28:20.870

Well that's weird, like I said it works fine here (Windows 7 English). Which version of Windows are you using? What install language is it (English, French, or ???)? – Ƭᴇcʜιᴇ007 – 2016-04-29T18:30:39.350

If you open a command prompt and run chcp, which code page is reported? – Ƭᴇcʜιᴇ007 – 2016-04-29T18:32:54.377

Using windows 7 as well - in English. but if it works for you, perhaps I'm having a windows issue... I'll have to test it on another pc – Bob G – 2016-04-29T18:33:52.897

Active code page: 437 – Bob G – 2016-04-29T18:34:22.303

Yup, that's the code page I would expect. Yeah that's just weird. :) Like I said it works fine here: image

– Ƭᴇcʜιᴇ007 – 2016-04-29T18:39:57.737

Yep.. so I tested that typing directly from cmd prompt, and it does in fact work. but not from the batch file itself.... – Bob G – 2016-04-29T18:53:34.260

chcp 1252 fixes the problem. Answer added. – DavidPostill – 2016-04-29T19:26:33.900

@Ƭᴇcʜιᴇ007 Works from the command line but not in a batch file. Changing the code page in the batch file fixes it (I'm not sure why exactly) – DavidPostill – 2016-04-29T19:37:02.987

The example picture I stick in my comment is a shot of it being run from a batch file.. Weird.. – Ƭᴇcʜιᴇ007 – 2016-04-29T19:43:36.227

Answers

0

After further investigation the issue was strange - Using chcp 1252 In a test.cmd - would work.... but for some reason would not work in me larger batch file. (I have honestly no idea why as I copied the text code for code

:TST
@echo off
cls
chcp 1252
echo d'interruption du système | CLIP
pause
goto Menu

However I found that adding the line chcp 65001 Worked for everything.

:TST
@echo off
cls
chcp 65001
echo d'interruption du système | CLIP
pause
goto Menu

Hopes this helps out.

Bob G

Posted 2016-04-29T18:14:41.317

Reputation: 11

1

The French accents are not copying properly

Add chcp 1252 (West European Latin) to the start of the batch file.

  • Without this I can reproduce your problem (my default code page is 850 - Multilingual (Latin I)
  • With it added I get the expected text on the clipboard.

Example 1:

F:\test>type test.cmd
echo systÞme | Clip
F:\test>test

F:\test>echo systÞme   | Clip

F:\test>systÞme
'systÞme' is not recognized as an internal or external command,
operable program or batch file.

Example 2:

F:\test>type test.cmd
chcp 1252
echo systÞme | Clip
F:\test>test

F:\test>chcp 1252
Active code page: 1252

F:\test>echo système   | Clip

F:\test>système
'système' is not recognized as an internal or external command,
operable program or batch file.

Notes:

  • In the above tests I just pasted the contents of the clipboard onto the command line.

  • Without the chcp the clipboard contained systÞme.

  • With chcp the clipboard contained système.


Further Reading

DavidPostill

Posted 2016-04-29T18:14:41.317

Reputation: 118 938

I have to laugh - Yes this works. In a simple batch file.. Thank you much for this... (but for some reason it does not work as part of the total batch file...) but there's some bug probably somewhere. Thanks for the help – Bob G – 2016-04-29T19:43:45.950

You're welcome ;) I still don't know why it is needed though. – DavidPostill – 2016-04-29T19:45:06.530