windows - 如何将多行命令行命令复制/粘贴到命令提示符中?

标签 windows windows-10 command-line-interface

我正在尝试将一些长的多行命令行命令复制/粘贴到 Windows 10 命令提示符中。

Linux为此使用“\”字符,因此例如在Linux中,您可以将以下内容从网站或文本文件复制/粘贴到终端窗口中(我假设在这里使用图形桌面环境):

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"

然后按回车,命令将运行。这在网站或您保存的文本文件中看起来更加清晰。

问题是,我似乎无法为此制定一个 Windows 等效项。我意识到 ^ 字符在这种情况下等同于 Linux\字符,但它似乎不适用于复制/粘贴。例如,如果创建一个文本文件“dummy1.txt”,则复制/粘贴以下内容:
copy dummy1.txt ^ 
    dummy2.txt

(注意第一行的^字符两边有一个空格)

我明白了:

enter image description here

对于这个两行示例,这无关紧要,但对于更复杂的命令(例如上面的 python 脚本),将所有需要复制/粘贴的文档放在一行中会严重牺牲可读性。有没有办法让它在 Windows 上运行?如果这很重要,我目前正在使用 Windows 10。

最佳答案

我认为您需要像这样对其进行 powershellafy:

$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
如果您只是想将行分成多行,则转义字符是反勾号 `
get-longcommand -name "long command" `
-date "today" `
-other-info "other stuff"
最后,请理解“Foreach”循环。有很多种,这里有一个简单的
$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
  }
可能有类似 $file.fullname 或类似的东西来传输路径。如果您使用 Powershell ISE,并使用调试例程,请在循环中的“$file”之后暂停,您可以看到详细信息。
享受!

关于windows - 如何将多行命令行命令复制/粘贴到命令提示符中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48173606/

相关文章:

windows - Docker 快速启动终端无法在 Windows 10 中启动 VirtualBox VM

c# - Windows 10 UWP 上的应用内购买问题

javascript - loadXml 在 Windows 10 上返回未定义

python - "subprocess.Popen().readline()"在多线程python中无法返回

java - 如何从 ant 调用 WSDL2JAVA,路径中存在空格

.net - 以编程方式监视文件上的 Windows #locks,如 compmgmt.msc 中所示

Docker:无法从 Spring Boot 应用程序读取类路径资源

php - npm 安装无法通过 php system() (exec/shell_exec) 工作

html - ng服务一次时如何防止自动重新加载页面?

linux - 如何为每个命令重定向文件中的 STDOUT 和 STDERR?