从另一个批处理文件更新一个批处理文件

从另一个批处理文件更新一个批处理文件

本文介绍了从另一个批处理文件更新一个批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的StackOverFlow成员,

Dear StackOverFlow Members,

请帮助我处理此批处理文件.我想使用"SET/P INPUT =%=%"中给出的答案,并使其永久更新另一个批处理文件.

Please help me with this batch file. I would like to use the answer given from the "SET /P INPUT=%=%" and have it update another batch file permanently.

这是第一个从用户那里得到答案的批处理文件

This is the first batch file that runs to get an answer from the user

@echo off
cls
echo.
echo .................................................................
echo ..... Specify what the name of the Store is, this will send .....
echo ............... alerts to [email protected] ..............
echo .................................................................
echo.
pause
:option
cls
color 5E
echo.
echo "............   Press 1 to specify what the store name is......"
echo "............   Press 2 to exit the program   ................."
echo.
SET /P M=Type from the menu above 1 or 2 then press ENTER:
IF %M%==1 GOTO SEND
IF %M%==2 GOTO EOF

:SEND
cls
color 0A
set INPUT=
set /P INPUT=Enter Store Name: %=%
if "%INPUT%"=="" goto input
echo "You said that the store name is: %INPUT%"

:: Have the user confirm his/her choice
SET /P ANSWER=Is the name correct (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
goto :no
:yes
echo You pressed YES!... The name is updating
goto name
:no
echo You pressed NO!... The program will exit
pause
cls
goto eof
:name
::set /A store=%INPUT%
echo %INPUT% >> notify_support.bat
::Terminate the program
:EOF

如您所见,我正在努力指定应该在哪里回显%INPUT%>> notify_support.bat".这是从第二个批处理文件中提取的代码

As you can see I am struggling to specify where I should "echo %INPUT% >> notify_support.bat". This is code taken from the second batch file

@echo off
call senditquiet -s smtp.gmail.com -port 587 -u [email protected] -protocol ssl -p access -f [email protected] -t [email protected] -subject "Store ABC" -body "Hello there, There is an issue logged at the store.<br>Best regards."

第一个批处理文件运行时,它将更新第二个批处理文件,但仅将其转储到文件末尾.

When the first batch file runs, it updates the second one but just dumps it at the end of the file.

我需要INPUT ECHOed来替换第二个批处理文件中的"Store ABC".

I need the INPUT ECHOed to replace "Store ABC" in the second batch file.

请协助,批处理文件让我感到非常生锈.

Please assist, I'm rather rusty with batch files.

推荐答案

echo %INPUT% >> notify_support.bat

该行包含>> ,这意味着在文件末尾转储".您可以使用单个> 覆盖现有文件内容.这样,您可以重新生成整个文件(无论如何只有2行).

That line contains >> which means 'dump at the end of the file'. You can use a single > to overwrite the existing file contents. That way, you can re-generate the whole file (which is only 2 lines anyway).

另一种解决方案是实际解析现有文件并替换该文本.您可以通过使用 for/F ... 来做到这一点,它使您可以遍历文件的各行.然后,您可以根据现有文件的(更改的)内容生成一个新文件.缺点是此文件解析方法特别适用于每行具有相同格式的字段和定界符的数据文件(例如CSV文件).它不适用于解析复杂"文件,例如批处理文件或程序源文件.

A different solution is to actually parse the exising file and replace that text. You can do that by using for /F ..., which allows you to traverse through the lines of a file. You can then generate a new file, based on the (altered) contents of the existing file. Disadvantage is that this file-parsing method is especially suitable for data files in which each line has the same format with fields and delimiters (like a CSV file). It is less suited for parsing 'complex' files like a batch file or program source file.

这篇关于从另一个批处理文件更新一个批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:33