1

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?

2

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).

4
  • (For apps that do not implement this feature) In other words, are you saying that it's not possible to "hack" around this limitation?
    – Pacerier
    Jan 10 '15 at 12:36
  • Once you've executed the app, no. However for PHP, you could try this: php.net/manual/en/features.commandline.interactive.php
    – justinsg
    Jan 10 '15 at 12:43
  • Ah, was thinking some sort of "standard" protocol would have been built by now to tackle this annoying issue....
    – Pacerier
    Jan 10 '15 at 13:58
  • @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.
    – TOOGAM
    Mar 5 '15 at 20:56
0

I know it's an old question, but my two cents:

First off, I'd advise writing everything as a script file wherever possible and just running php <filename>, but I realise that's not the point of the question.

If I do just want to test something reeeally quick (let's say I've forgotten if array_flip returns a flipped array, or does it flip the original?) then I use the -r flag:

C:\PHP>php -r "$arr = array(5,6,7); $arr2 = array_flip($arr); print_r($arr); print_r($arr2);"

You can backspace all you want as you're still in the command shell, not the PHP shell.

(Also you can save yourself precious tenths of seconds by just typing php instead of php.exe)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.