【问题标题】:CMD Set only reading first letter in text fileCMD 设置只读取文本文件中的第一个字母
【发布时间】:2018-04-11 17:28:08
【问题描述】:

使用以下命令Set /p out=<out.txt我没有得到
文件中的文本,返回的只是一个符号和文件中的第一个字母。

我试过使用Set out=more out.txt,但最终只是将
命令“more out.txt”放入脚本而不是文本文件中。
https://i.stack.imgur.com/yU9A1.jpg

【问题讨论】:

    标签: variables cmd set output command-prompt


    【解决方案1】:

    看起来out.txt 是使用UTF-16 encoding with BOM 保存的。与type command 不同,< redirection operator 不理解这一点。以下cmd 命令应该可以解决问题:

    set out=&for /f "delims=" %G in ('type out.txt') do @if not defined out set out=%G
    

    要在批处理脚本中使用 FOR 命令(.bat.cmd 扩展名),请指定 %%G %G 如下:

    @ECHO OFF
    set "out="
    for /f "delims=" %%G in ('type out.txt') do if not defined out set out=%%G
    

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 2010-12-26
      相关资源
      最近更新 更多