Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to copy multiple lines from the Windows Command Prompt without it inserting a new line where each line reaches the end of the terminal?

For example, if I have the following line in the console:

c:\very_long_path_here\more_path_here>command_i_want_to_copy -with -some
arguments that wrap over lines.

If I select this and copy it, I will get a newline after the word 'some', which I'll have to delete manually.

Is there a way to copy the data (command that will be parsed, output that is printed) in the form it is interpreted/printed, rather than with hard-wrapped lines?

share|improve this question
1  
In Win 7/8 there is a clip.exe, which redirects input to clipboard. You can use it like c:\> echo your -command | clip.exe. But it's more suitable for a command output.. – week Mar 15 '13 at 10:37
    
afaik there is no built in way to do this. but maybe you can combine something like a short autoit script with clip.exe to archive your goal – weberik Mar 15 '13 at 12:41
    
since windows 10 the default behavior will wrap the line selection so no more problem – Lưu Vĩnh Phúc Jan 11 at 6:53
up vote 3 down vote accepted

The Windows Command Prompt is notoriously broken in this aspect. It is not possible to get the Linux Terminal behavior (at least for pre-Windows 10 according to Luu's comment).

However, there is an obscure feature in cmd.exe which helps: Holding down shift when right clicking into the selected area (to copy) will remove ALL newlines in the copied text.

If you want to select a single long command line (spanning multiple terminal lines) this does what you want. However, it will always remove all newlines, so it is not possible to select multiple command lines (or a script) in a sensible way.

Detailled procedure:

  • Select long command line using the left mouse button
  • Press down shift
  • Right click into the selected area (to copy)
  • Release shift
  • Now the selected text is in the copy buffer without newlines and you can for example paste it into cmd.exe again using the right mouse button
share|improve this answer
    
Interesting, I'd never heard of that feature. It looks like that's as good as it's going to get. I don't use windows anymore, but when I get the chance to confirm it I'll accept this answer. :-) – Adam Millerchip Oct 9 '15 at 2:32
    
since windows 10 you'll get Linux behavior by default – Lưu Vĩnh Phúc Feb 20 at 3:09
    
... so "It is not possible to get the Linux Terminal behavior" is incorrect – Lưu Vĩnh Phúc Feb 23 at 7:08
    
@Luu: Thanks for adding the info about Windows 10. But what do you mean with 'by default'? This suggests that there is an alternative behavior for pre-Windows 10 systems, which there isn't, so your comment is misleading. Also: Who is using Windows 10? (SCNR) – Johannes Overmann Feb 25 at 13:59

Another option is to open the context menu of the console window's title bar, go to Properties and make the screen buffer's width large enough that things don't wrap. (9999 appears to be the maximum value.)

If you're having to do this a lot, you can change the option in Defaults instead of Properties.

Of course, this method breaks down if the lines are longer than 9999 characters.

share|improve this answer
1  
Nice idea, too! Less obscure to use, but less visibility. – Johannes Overmann Feb 25 at 14:01
1  
@Abraxas I've rewritten the answer in much more detail. – 1j01 Mar 4 at 5:21

Use the SET and then combine the parts in the expression. Additionally you can do for such purposes batch file or macro.

@set WAIKTools=%ProgramFiles%\WAIK\Tools\amd64
@set LabelCD=GRTMPVOL_RU

@IF "%time:~0,1%" GTR "0" SET current=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%@%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%
@IF "%time:~0,1%" LSS "0" SET current=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%@0%TIME:~1,1%.%TIME:~3,2%.%TIME:~6,2%

"%WAIKTools%\oscdimg.exe" -h -m -n -l%LabelCD% -b"%cd%\boot\w32sp3.bif" "BUILD-%current%" "BUILD-%current%-ISO\%LabelCD%.ISO"
share|improve this answer
    
This answer has nothing to do with the question. Where is the copy part? Where is the Windows terminal part? – Johannes Overmann Apr 20 at 22:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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