Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 用cmd命令的输出替换文本文件中固定位置的字符串_Windows_Cmd - Fatal编程技术网

Windows 用cmd命令的输出替换文本文件中固定位置的字符串

Windows 用cmd命令的输出替换文本文件中固定位置的字符串,windows,cmd,Windows,Cmd,我想用Windows CMD中hostname命令的输出替换位于c:\BR.txt的文本文件第3行中的QUICKSERVER字符串。hostname是一个返回系统名的Windows命令 C:\>hostname QUICKSERVER 我的文本文件是: userName=Administrator password= CMS=QUICKSERVER:6400 authentication=secEnterprise 请在Windows命令行中找到我可以执行的命令,以便用

我想用Windows CMD中hostname命令的输出替换位于c:\BR.txt的文本文件第3行中的QUICKSERVER字符串。hostname是一个返回系统名的Windows命令

C:\>hostname
QUICKSERVER
我的文本文件是:

  userName=Administrator
  password=
  CMS=QUICKSERVER:6400
  authentication=secEnterprise

请在Windows命令行中找到我可以执行的命令,以便用QUICKSERVER替换主机名

主机名也可以在%computername%环境变量中找到,因此不需要hostname命令

@echo off
setlocal enabledelayedexpansion
for %%L in (c:\br.txt) do (
  set "LINE=%%L"
  set "LINE=!LINE:QUICKSERVER=%COMPUTERNAME%!"
  echo !LINE!
) > C:\br2.txt
move /y C:\br2.txt c:\br.txt