chcp — Set or query ASCII/EBCDIC code pages for the terminal

Format

Description

chcp sets, resets, or queries the current ASCII/EBCDIC code conversion in effect for the controlling terminal. Use it when the terminal requires ASCII data and the shell application uses EBCDIC. Do not use chcp if you are logged on through the TSO/E OMVS command. The _BPX_TERMPATH environment variable enables shell scripts to tell if the user logged on from TSO, rather from rlogin or telnet.

Options

–a ASCII_cp
The name of the ASCII code page used by the terminal. EBCDIC data from the shell application is converted to this ASCII code page before it is sent out to the terminal. Data from the terminal is converted from this ASCII code page to EBCDIC before the application receives it.

The name of the ASCII code page is case-sensitive.

For a list of code pages supported by the shell, see z/OS XL C/C++ Programming Guide.

–e EBCDIC_cp
The name of the EBCDIC code page used for this session. EBCDIC data from the shell application is converted from this EBCDIC code page to ASCII before it is sent out to the terminal. ASCII data from the terminal is converted to this EBCDIC code page before the application receives it.

The name of the EBCDIC code page is case-sensitive.

For a list of code pages supported by the z/OS shell, see z/OS XL C/C++ Programming Guide.

–q
Queries the current ASCII and EBCDIC code pages for this terminal. The results are written to standard output. You cannot use any other options if you use the –q option.
–r
Resets the ASCII/EBCDIC conversion for the terminal to the default code pages. The default ASCII code page is ISO8859-1, and the default EBCDIC code page is IBM-1047.

You cannot use –r with any other options.

–s
Specifies that the ASCII/EBCDIC conversion for the terminal is to use the code pages specified by the –a and –e options. You cannot use –s with any other options other than –a or –e. Either –a or e (or both) must also be specified if –s is used.
The chcp query output is written to standard output. For example, if you enter
chcp –q
You get the following output:
Current ASCII  code page = ISO8859-1
Current EBCDIC code page = IBM-1047

Examples

  1. To set the ASCII and EBCDIC code pages to IBM-eucJP and IBM-939, enter:
    chcp –a IBM-eucJP –e IBM-939
  2. To change just the EBCDIC code page to IBM-277, enter:
    chcp –seIBM-277
  3. To change just the ASCII code page to IBM-850, enter:
    chcp –a IBM-850
  4. To reset ASCII/EBCDIC code page conversion to the default code pages for this terminal, enter:
    chcp –r
  5. To query the current ASCII and EBCDIC code pages for this terminal, enter:
    chcp –q

Usage notes

  1. Do not use chcp when you are logged on from the TSO/E OMVS command because the OMVS command does not do any ASCII/EBCDIC code page conversion.

    Shell scripts can test the _BPX_TERMPATH environment variable and bypass chcp when the user is logged on through OMVS. (The _BPX_TERMPATH environment variable enables shell scripts to tell if the user logged on from TSO/E rather than from rlogin or telnet.)

    Before starting the session, the TSO/E OMVS command sets _BPX_TERMPATH to “OMVS”.

    Sample shell script code:
    #  -----------------------------------------------
    #  Issue chcp only if not using TSO/E OMVS command
    #  -----------------------------------------------
    
    if
    test "$_BPX_TERMPATH" != "OMVS"
    then
    chcp –a IBM-850 –e IBM-1047
    fi
  2. After running chcp –s to change the EBCDIC code page for the session, you may also need to alter or set the following environment variables to match the new code page:
    • LANG
    • LC_ALL
    • LC_COLLATE
    • LC_CTYPE
    • LC_MESSAGES
    • LC_SYNTAX
    • NLSPATH
  3. The code page names supplied with the –a and –e options are passed to iconv_open() without any uppercase or lowercase conversion. Code page converters that convert between the specified ASCII and EBCDIC code pages must be available for iconv().
  4. If ASCII/EBCDIC conversion is not active for this terminal, both the ASCII and EBCDIC code pages must be specified on the chcp –s command. At other times, omit –a when just the EBCDIC code page needs to be changed. Omit –e when just the ASCII code page needs to be changed.
  5. All code pages with names not known to chcp are considered to be single-byte (SBCS) user-defined code pages. User-defined multibyte code pages are not supported.
  6. chcp cannot check user-defined code page names to make sure that –a really specifies an ASCII code page and –e specifies an EBCDIC code page. In this case, specifying the wrong code pages may cause terminal input and output to be completely unreadable. It may also be impossible to enter any more shell commands.
  7. chcp operates on the controlling terminal.
  8. chcp should not be run as a background job.
  9. The –d option specifies that special debugging information be printed. Specify this option only when requested by IBM®.

Localization

chcp uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion
1
Incorrect command-line arguments or options
2
Any of the following errors:
  • There is no controlling terminal.
  • The controlling terminal does not support ASCII/EBCDIC code page conversion (the TSO/E OMVS command, for example).
  • iconv_() fails when passed the code page names specified on the command line.
  • chcp cannot build SBCS conversion tables using iconv() when required.
  • An I/O error occurred on the controlling terminal.
  • Either the –a or –e was omitted and the chcp –s command was run while the terminal code page conversion is in binary mode.

Portability

None. chcp is not described in any standard.

Related information

lm, rlogin