Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6989431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:12:40+00:00 2026-05-27T19:12:40+00:00

Why CTRL + M gives an ASCII value of 10 (decimal value). It should

  • 0

Why CTRL + M gives an ASCII value of 10 (decimal value). It should actually give 13. I am connecting to Amazon EC2 linux instance through putty. I execute the below program

import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;

public class NumbersConsole {

private static String ttyConfig;

public static void main(String[] args) {

        try {
                setTerminalToCBreak();

                int i=0;
                while (true) {

                        //System.out.println( ""+ i++ );

                        if ( System.in.available() != 0 ) {
                                int c = System.in.read();
                    System.out.println(c);
                                if ( c == 13 ) {
                                        break;
                                }
                        }

                } // end while
        }
        catch (IOException e) {
                System.err.println("IOException");
        }
        catch (InterruptedException e) {
                System.err.println("InterruptedException");
        }
        finally {
            try {
                stty( ttyConfig.trim() );
             }
             catch (Exception e) {
                 System.err.println("Exception restoring tty config");
             }
        }

}

private static void setTerminalToCBreak() throws IOException, InterruptedException {

    ttyConfig = stty("-g");

    // set the console to be character-buffered instead of line-buffered
    stty("-icanon min 1");

    // disable character echoing
    stty("-echo");
}

/**
 *  Execute the stty command with the specified arguments
 *  against the current active terminal.
 */
private static String stty(final String args)
                throws IOException, InterruptedException {
    String cmd = "stty " + args + " < /dev/tty";

    return exec(new String[] {
                "sh",
                "-c",
                cmd
            });
}

/**
 *  Execute the specified command and return the output
 *  (both stdout and stderr).
 */
private static String exec(final String[] cmd)
                throws IOException, InterruptedException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    Process p = Runtime.getRuntime().exec(cmd);
    int c;
    InputStream in = p.getInputStream();

    while ((c = in.read()) != -1) {
        bout.write(c);
    }

    in = p.getErrorStream();

    while ((c = in.read()) != -1) {
        bout.write(c);
    }

    p.waitFor();

    String result = new String(bout.toByteArray());
    return result;
}

}

and when I give the input as (CTRL + M), I am getting displayed a value of 10. But I am expecting a value of 13. Please let me know if I am missing anything??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:12:41+00:00Added an answer on May 27, 2026 at 7:12 pm

    The translation of CR to LF is handled by the tty driver. You’re calling setTerminalToCBreak(), which manipulates the tty settings (I think it disables the erase, kill, werase, and rprnt special characters).

    The icrnl setting, which is enabled by default, causes carriage return (CR) to be translated to newline (LF). Disabling that should let you see CR characters directly. Setting raw mode changes a number of flags, including turning off icrnl. (Figuring out how to do that in Java is left as an exercise.)

    But beware of doing this. The Enter or Return key typically sends a CR character. Translating it to LF is what allows it to mark the end of a line. If you turn off that translation, you might break that behavior unless you handle CR yourself.

    For more information on tty settings, man tty or follow this link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I press Ctrl + B that ought to give me ASCII code 2,
C-b: gives you tmux command prompt. Is there a way to scroll through the
I want to do a reverse search in unix shell. The Ctrl-R gives me
Ctrl-Shift-B, by default, builds an entire solution. An entire solution may contain many projects.
Ctrl M-L doesn't toggle all the regions in vb.net (2008) when there's a hierarchy
While Ctrl X works fine in vim under windows, Ctrl A selects all (duh).
I'm using Ctrl + Left / Ctrl + Right in a GreaseMonkey script as
I know the combination Ctrl + A to jump to the beginning of the
When I use CTRL + H I end up on the Java Search tab.
The new awesome Ctrl + . keyboard shortcut to show smart tags has suddenly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.