cdahms
cdahms

Reputation: 3750

How to copy/paste multi-line command line command into Command Prompt?

I'm attempting to copy/paste some long, multiple line command line commands into a Windows 10 Command Prompt.

Linux uses the "\" character for this, so for example in Linux you could copy/paste the following from a website or text file into a terminal Window (I'm supposing using a graphical desktop environment here):

python retrain.py \
    --bottleneck_dir="/tf_files" \
    --how_many_training_steps=500 \
    --model_dir="/tf_files" \
    --output_graph="/tf_files/retrained_graph.pb" \
    --output_labels="/tf_files/retrained_labels.txt" \
    --image_dir="/tf_files/flower_photos"

Then press enter and the command will run. This looks much more clear on a website or in a text file you've saved.

Problem is, I can't seem to work out a Windows equivalent for this. I realize the ^ character is equivalent to the Linux \ character in this context, but it does not seem to work for copy/paste. For example, if make a text file "dummy1.txt", then copy/paste in the following:

copy dummy1.txt ^ 
    dummy2.txt

(note there is a space on both sides of the ^ character on the 1st line)

I get this:

enter image description here

For this two line example this does not matter, but for more elaborate commands such as the python script above, putting everything on one line in any documentation that needs to be copies/pasted out of sacrifices readability severely. Is there a way to get this to work on Windows? I'm using Windows 10 currently if that matters.

Upvotes: 12

Views: 24918

Answers (2)

DWB
DWB

Reputation: 387

Why try pasting a command with spaces after the caret? The example linux code given by the OP did not include spaces after the line breaking "\" backslashes. The comment by @Eryk explained that the caret needs to escape the line break.

Here are ready to paste snippets for the win 10 command prompt; the 1st without trailing spaces after the carets, and the 2nd with one space after its first caret.

dir C:\Windows ^
    /A-D ^
    /OS

dir C:\Windows ^ 
    /A-D ^
    /OS

Expect the 1st snippet, broken into three lines, to execute as a single command, and the 2nd snippet, with its trailing space, to unsuccessfully execute as two commands.

Upvotes: 0

Technoob1984
Technoob1984

Reputation: 172

I think you need to powershellafy it like this:

$retrain =  @{
    bottleneck_dir = “/tf_files”
    how_many_training_steps = “500"
    model_dir= "/tf_files"
    output_graph = "/tf_files/retrained_graph.pb"
    output_labels = "/tf_files/retrained_labels.txt"
    image_dir = "/tf_files/flower_photos"
}
#imaginary equivalent script  
retrain.ps1 $retrain

If you are simply looking to break lines into multiple lines the escape character is a back tick `

get-longcommand -name "long command" `
-date "today" `
-other-info "other stuff"

Lastly, please understand a 'Foreach' loop. There are multiple kinds, here is an easy one

$copy_list = @(get-childitem "C:\Path\to\files")
$new_dest = "C:\New\File\Destination"

foreach ($file in $copy_list) { 

#This is for troubleshooting, outputs which file it is running
  $file
  copy-item -Path $file -Destination $new_dest
  }

There may be something like $file.fullname or something like that to transfer the path. If you use Powershell ISE, and use the debug routine, pause right after '$file' in the loop, and you can see the details.

Enjoy!

Upvotes: 1

Related Questions