2

我想从另一个批处理创建一个批处理文件。那么我如何在新蝙蝠中编写代码,而不在原始蝙蝠中执行呢?到目前为止,我的代码是:

SET var1=%~dp0
SET var2
for %%a in ("%cd%") do set var2=%%~na
echo bla %var1% bla >> build%var2%.bat

应该有多行代码,而不是“bla”。我该如何存档?

编辑:

现在我的代码如下所示:

SET var1=%~dp0
SET var2
for %%a in ("%cd%") do set var2=%%~na

SET string = (
echo SET mdbname=%var2%
echo SET OfficeDIR=%%ProgramFiles(x86)%%\Microsoft Office\Office14
echo SET WorkDIR=%var1%
echo md build

echo copy %%mdbname%%.mdb build\%%mdbname%%.mda /Y
echo "%%officedir%%\msaccess.exe" /compact "%%WorkDir%%\build\%%mdbname%%.mda" 

echo "D:****.exe" "%%WorkDir%%\build\%%mdbname%%.mda" "D:\****** Key - Nicht weitergeben" "%%officedir%%"

echo copy "%%WorkDir%%\build\%%mdbname%%.mda" "%%ProgramFiles(x86)%%\*******" /Y
)
echo %string% >> built%var2%.bat

但在新创建的批次中,只写了:“ECHO ist eingeschaltet (ON)”。/ "ECHO 已激活 (ON)。"

编辑2:

现在看起来像这样,什么也没有发生,甚至没有创建文件

SET var1=%~dp0
SET var2
for %%a in ("%cd%") do set var2=%%~na

(echo SET mdbname=%var2%
echo SET OfficeDIR=%%ProgramFiles(x86)%%\Microsoft Office\Office14
echo SET WorkDIR=%var1%
echo md build

echo copy %%mdbname%%.mdb build\%%mdbname%%.mda /Y
echo "%%officedir%%\msaccess.exe" /compact "%%WorkDir%%\build\%%mdbname%%.mda" 

echo "D:\TFS\RepV\RepV 6.1\ITPBuildTool61.exe" "%%WorkDir%%\build\%%mdbname%%.mda" "D:\TFS\RepV\RepV 6.1\ITPEAK.OLKey Private Key - Nicht weitergeben" "%%officedir%%"

echo copy "%%WorkDir%%\build\%%mdbname%%.mda" "%%ProgramFiles(x86)%%\Sage\Office Line\6.1\Addin\Work" /Y) > built%var2%.bat
4

2 回答 2

3

此处基于jeb 的答案是您的代码与应用原则。

@echo off
set "var1=%~dp0"
set "var2="
for %%A in ("%cd%") do set "var2=%%~nA"

(
echo @echo off
echo set "mdbname=%var2%"
echo set "OfficeDIR=%%ProgramFiles(x86)%%\Microsoft Office\Office14"
echo set "WorkDIR=%var1%"
echo md build

echo copy "%%mdbname%%.mdb" "build\%%mdbname%%.mda" /Y
echo "%%officedir%%\msaccess.exe" /compact "%%WorkDir%%\build\%%mdbname%%.mda" 

echo "D:\TFS\RepV\RepV 6.1\ITPBuildTool61.exe" "%%WorkDir%%\build\%%mdbname%%.mda" "D:\TFS\RepV\RepV 6.1\ITPEAK.OLKey Private Key - Nicht weitergeben" "%%officedir%%"

echo copy "%%WorkDir%%\build\%%mdbname%%.mda" "%%ProgramFiles(x86)%%\Sage\Office Line\6.1\Addin\Work" /Y
) > built%var2%.bat

echo %cd%
type built%var2%.bat
pause

这对我有用,并在工作目录中创建一个包含以下内容的文件。

@echo off
set "mdbname=Desktop"
set "OfficeDIR=%ProgramFiles(x86)%\Microsoft Office\Office14"
set "WorkDIR=C:\Users\User\Desktop\"
md build
copy "%mdbname%.mdb" "build\%mdbname%.mda" /Y
"%officedir%\msaccess.exe" /compact "%WorkDir%\build\%mdbname%.mda"
"D:\TFS\RepV\RepV 6.1\ITPBuildTool61.exe" "%WorkDir%\build\%mdbname%.mda" "D:\TFS\RepV\RepV 6.1\ITPEAK.OLKey Private Key - Nicht weitergeben" "%officedir%"
copy "%WorkDir%\build\%mdbname%.mda" "%ProgramFiles(x86)%\Sage\Office Line\6.1\Addin\Work" /Y
于 2013-11-06T17:06:56.487 回答
2

使用所有特殊字符回显所有行echo并转义所有特殊字符。
&|<>前面需要插入符号或引号。
%需要加倍。

(
  echo @echo off
  echo echo This is batch2
  echo set var=abc
  echo echo %%var%%
  echo echo redirect ^> file2.ttx
) > build%var2%.bat
于 2013-11-06T16:17:26.757 回答