Chcp is not recognised as an internal or external command - windows

'chcp' is not recognized as an internal or external command,
operable program or batch file.
Password for user postgres:
psql (14.3)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.

You can probably find the answer here: https://www.computerhope.com/chcphlp.htm#:~:text=The%20chcp%20command%20is%20used,be%20loaded%2C%20and%20the%20country.
The chcp command is used to supplement the international keyboard and
character set information, allowing MS-DOS to be used in other
countries and with different languages. Before the chcp command can be
used, the nlsfunc must be loaded, and the country.sys must be loaded
into the config.sys.

Related

Batch script does not change console code page from command prompt

When running psql <database_name> from the command line I've been getting this warning:
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
I found a solution for this found from another question however it only gets rid of the warning for that session and I'm trying to completely get rid of the warning. It's been mentioned that I could go into C:\Program Files\PostgreSQL\9.6\scripts\runpsql.bat and cmd.exe /c chcp 1252 or chcp 1252 near the top of the batch file to remove this warning, however that has not been working for me.
When executing the batch file, it does print out a line console code page and the warning doesn't appear. However when I run psql [database] from the command prompt, the warning still persists. Does anyone know how to permanently remove the warning?
I am using PostgreSQL 9.6.1 and Windows 7 64-bit.
Look here: psql: Init files?
You can locate the file PSQLRC.CONF and add in it a line like, perhaps,
\set ENCODING "whatever encoding you want"

CMD: '■m' is not recognized as an internal or external command

I am trying to get a batch file to work. Whenever I attempt to run a .bat the command line returns '■m' is not recognized... error, where "m" is the first letter of the file. For example:
md c:\testsource
md c:\testbackup
Returns
C:>"C:\Users\Michael\Dropbox\Documents\Research\Media\Method Guide\Program\test
.bat"
C:>■m
'■m' is not recognized as an internal or external command,
operable program or batch file.
Things I have tried:
Changing Path variables, rebooting, etc.
Changing file directory (i.e. run from C:)
Running example files from web (like above) to check for syntax errors.
Thanks
What text editor are you writing this in? It seems like your text editor may save the file as UTF-16 encoded text, which cmd.exe can't handle. Try setting the "coding"/"file encoding" to "ANSI" when saving the file.
This results in the first byte being a byte-order-mark (telling other editors how to process the file), and cmd.exe can't deal with this.
In addition to the approved answer I would add the case where is a PowerShell command the one that creates the file... PowerShell comes by default with the UTF-16 encoding.
To solve your problem then, force the file encoding lie this: | out-file foo.txt -encoding utf8
Answer based on this other answer.
In windows 10 I had the same issue.
Changing the character set to UTF-8 made it worse.
It worked correctly when I selected Encoding as UTF-8-NO BOM.

psql shell uses code page 850, windows uses 1252. How to solve change console code page?

I have installed PostgreSQL, wanting to set up a new database, everything is going fine, until I am trying to use the € sign. And then I knew, that warning I get in the beginning is for a reason.
The warning I am getting at starting up my psql shell is:
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
So I am going to do as I am told (from PostgreSQL Documentation 9.2 - psql):
Notes for Windows Users
psql is built as a "console application". Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8-bit characters within psql. If psql detects a problematic console code page, it will warn you at startup. To change the console code page, two things are necessary:
Set the code page by entering cmd.exe /c chcp 1252. (1252 is a code page that is appropriate for German; replace it with your value.) If you are using Cygwin, you can put this command in /etc/profile.
Set the console font to Lucida Console, because the raster font does not work with the ANSI code page.
When I type the cmd.exe /c chcp 1252 command I get a syntax error. So psql, doesn't recognize the command.
Out of desperation, I was trying to do something in cmd.exe itself, does not work either.
I work in Windows 7 - 64Bit.
What is your database Character Set? If it is UTF-8, then before running, what ever you want in psql, just tell the console to use the UTF-8 encoding:
cmd.exe /c chcp 65001
I had the same problem in Windows 10.
In psql type ! chcp
it revealed my setting as 850. This I changed to 1252 by doing the following.
! dir revealed a file runpsql.bat in C:\Program Files\PostgreSQL\9.6\scripts
From windows after exiting psql I ran Notebook in Administrator mode and added above the REM Run psql statement the command chcp 1252
Now runs without the warnings
As far as I know, in SQL shell you just need to type \! chcp <codepage_you_need>.
Still, after that, you might encounter another issue:
In order to solve this problem you need to go to properties (left upper corner) -> Fonts -> choose Lucida Console.
Then type \! chcp 1251
After that, everything must be alright.
I was able to fix this by running SET CLIENT_ENCODING TO 'UTF-8'; in the sql bash
I had the same problem in Windows 8.
You have to set the chcp to 1252.
With the command cmd.exe /c chcp 1252, or, if you are using powershell: powershell /c chcp 1252.
You can also use powershell /c chcp 1252.
But you have to type it before enter in the psql console.
Edit runpsql.bat (folder ...\PostgreSQL\XX\scripts)
On the next line after #echo off write: cmd /c chcp 1252 and save (you need admin permissions).
Screenshot runpsql
Results

my.bat not recognized as an internal or external command, operable program or batch file

When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is:
C:\Users\SVC_asl2trim>
So I added this to the PATH and then I issued:
C:\Users\SVC_asl2trim>set path
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;D:\Program Files\Hewlett-Packard\HP TRIM\;C:\Users\SVC_
asl2trim\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
C:\Users\SVC_asl2trim>
I have a small .bat file in that directory above but I keep getting:
my.bat not recognized as an internal or external command, operable program or batch file
This is maddening. I do this so infrequently .... I know there is some trick I am forgetting.
My stupid mistake...
Credit should go to Dennis for verifying that my.bat should work but as he surmised, it was not named that. I thought I had renamed it correctly from my.txt to my.bat but the problem was that it was actually named my.bat.txt ! Fixing that was key to this problem.
I was getting this error because my batch file was not ascii encoded; it was utf-8.
Since UTF and UCS often contain a BOM at the start of the file, make sure to save it as ASCII or UTF-8 without the BOM.
If you really need an alternate encoding, making the first line blank can sometimes work (for me the UTF-8 BOM doesn't stop execution, but the USC-2 one does). Both will print an error message from the first line, so it's not an ideal solution.

Why is there a difference between the encoding of the Windows Command Prompt vs. a batch file?

For example, suppose I have a batch file called 'test.cmd' and it simply contains:
echo %1
I can call this directly from the command prompt with 'test.cmd some¬arg' and the result is that the string 'some¬arg' is printed.
However if I place that same call in a second batch file, called 'tester.cmd' for the sake of argument, and I call this from the command prompt the result is that the string 'some%arg' is printed.
What is it that messes up the encoding and how do I get around it? I am sure I've fixed this before, but I can't remember how...
Thanks!
This is because your batch file is encoded in a different code page than cmd.exe is currently in.
In western default configurations, cmd.exe starts in CP850, but text editors usually work in CP1252 (what is often wrongly referred to as Latin-1 or ISO-8859-1).
The characters "¬" and "¼" share the same character code in these two code pages, "BC".
The solution is simple. Either encode your batch file in code page 850, or switch cmd.exe to code page 1252 by issuing chcp 1252.

Resources