I'm using Windows 10. Most often I copy/paste some command into the command prompt that needs to be modified say for example

composer create-project laravel/laravel blog "5.1.*"

I copied pasted the command from Laravel docs and blog needs to be changed.

The thing is, as soon as I paste it, the command prompt starts executing it, I think it's detecting a space at the end of the line somewhere. Can that be fixed?

  • 6
    If you have included a new-line in the pasted text, the command will be executed immediately. Omit the new-line, and the text will stay on the input line until Enter is pressed, allowing it to be edited first. – AFH Dec 6 at 11:31
  • 1
    A workaround in cmd.exe is to type rem+space, paste the command, let it be ignored, hit up key, remove rem and edit freely. – Kamil Maciorowski Dec 6 at 11:43
  • 1
    Just be selective about what you copy from the source file. If you copy the carriage return, it'll paste into command prompt as a carriage return. if you edit your source file in Notepad++, you can enable to ability to view > show symbol > all characters which will show a |CR| |LF| at the end of each line – spikey_richie Dec 6 at 12:43
  • 1
    Just to add to what @spikey_richie have already said, if you use Ctrl + A to select the entire text, it also select a carriage return at the end. So you may have to avoid it. – Cricrazy Dec 6 at 15:02
  • 2
    If you select by dragging from the end of the string instead of the beginning, you are less likely to include an inadvertent trailing new-line. – AFH Dec 6 at 15:17
up vote 2 down vote accepted

If you paste text with a trailing new-line into cmd, then the text will be executed as a command immediately.

The easiest way I have found to avoid this is to select by clicking at the end of the text, then dragging to the beginning. If you accidentally include an extra new-line it will be before the text, which will execute a blank line, before filling the next line with the text you want, but not executing it.

Alternatively, you could use Kamil Maciorowski's suggestion, to type rem (or ::) at the start of the line before pasting, so that if the line does execute, it will be a comment, which can then be edited with history editing or cutting and pasting within cmd itself.

This effectively does what you ask, stopping a pasted command executing immediately, even if there is a trailing new-line, though I prefer to make sure that there is no new-line in the pasted text.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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