How to backspace the characters in the cmd buffer?

5,212

CMD does support the backspace key, and it does work as you describe when you're typing a command before executing it.

Once you've begun the command (php.exe in this case) then STDIN is attached to that program (not CMD) and therefore it's up to that program whether it implements or allows backspacing or not.

To the program, the backspace key is just another character that it needs to process (e.g. ASCII #8).

Share:
5,212

Related videos on Youtube

Pacerier
Author by

Pacerier

# 9

Updated on September 18, 2022

Comments

  • Pacerier
    Pacerier over 1 year

    If we use command prompt to run short scripts as such:

    C:\php> php.exe
    
    <?php
    echo 'test';
    ?>
    

    , the output would be displayed directly in the command prompt:

    test
    ^C
    C:\php> 
    

    So let's say there are typo errors and I'd like to do a "backspace".

    E.g. assuming we mistyped echo as echoo:

    C:\php> php.exe
    
    <?php
    echoo 'test';
    

    How can I achieve "backspace" behavior on cmd without having to abort the full script and retype everything from scratch?

  • Pacerier
    Pacerier over 9 years
    (For apps that do not implement this feature) In other words, are you saying that it's not possible to "hack" around this limitation?
  • justinsg
    justinsg over 9 years
    Once you've executed the app, no. However for PHP, you could try this: php.net/manual/en/features.commandline.interactive.php
  • Pacerier
    Pacerier over 9 years
    Ah, was thinking some sort of "standard" protocol would have been built by now to tackle this annoying issue....
  • TOOGAM
    TOOGAM about 9 years
    @Pacerier : Nope: The keyboard buffer was supported by the old BIOS systems from way back in the pre-486 days. It was limited to 16 keystrokes, I think. Pressing backspace would use up another one of those 16 remembered keystrokes, not remove one. Nowadays technology may have advanced; maybe operating systems support unlimited buffers these days, I don't know. But the behavior is still based on the design of compatibility with the old standard. Since so many people are attached to using rodents, improving experiences keyboard buffers has not been widely viewed as a very critical priority.