以下是我正在使用的代码:
@ECHO OFF
IF "%1" == "start" (
SET /p %CmdLineArgs% =< commandLine.txt
START C:\edm\NewGenFH60.exe %CmdLineArgs%
) ELSE (
SET /p CmdLineArgs=Command Line Arguments:
ECHO you typed %CmdLineArgs%
ECHO %CmdLineArgs% > commandLine.txt
)
PAUSE
当我运行此代码时,commandLine.txt文件会填充“ECHO is OFF”,输出为“You typed”,我不知道为什么。
当我只运行这部分时:
SET /p CmdLineArgs=Command Line Arguments:
ECHO you typed %CmdLineArgs%
ECHO %CmdLineArgs% > commandLine.txt
在单独的批处理文件中按预期工作,commandLine.txt文件将填入我输入的任何内容。
当我从cmd行运行时,.bat文件似乎有效,但是当我单击桌面上的.bat文件时,它不会运行。有谁知道这是为什么?
答案 0 :(得分:1)
您需要使用DelayedExpansion
@ECHO OFF
setlocal enabledelayedexpansion
IF "%1" == "start" (
SET /p %CmdLineArgs% =< commandLine.txt
START C:\edm\NewGenFH60.exe %CmdLineArgs%
) ELSE (
SET /p a=Command Line Arguments:
ECHO you typed !a!
ECHO !a! > commandLine.txt
)
PAUSE
答案 1 :(得分:0)
试试这个:
@ECHO OFF &setlocal enabledelayedexpansion
IF "%1"=="start" (
SET /p CmdLineArgs=< commandLine.txt
START C:\edm\NewGenFH60.exe !CmdLineArgs!
) ELSE (
SET /p CmdLineArgs=Command Line Arguments:
ECHO you typed !CmdLineArgs!
ECHO !CmdLineArgs! > commandLine.txt
)
PAUSE