我得到了我的批处理文件以打开cmd提示符并成功更改目录,但是我无法工作的是在目录更改后我希望批处理然后输入字符串作为命令。
我已经尝试了cmd /k string
,但这似乎不起作用,cmd只是位于更改的目录中。我也试过了:
set Opvar= echo string
%Opvar%
它再次位于最后更改的目录中。注释掉的batchisp行是我想要表现的字符串,就像我键入整个字符串并在当前目录提示符处按Enter键一样。 这就是整个事情:
@Echo OFF
FOR /F "Tokens=*" %%@ IN ('Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" ^| FIND "-1000"') DO (
FOR /F "Tokens=2,*" %%A IN ('Reg Query "%%@" /v "ProfileImagePath" ^| FIND /V "%%@"') DO (
set drive=%%B
Echo Admin SID: %%~n@
Echo Admin Folder: %%B
)
)
:Ask
echo What are you flashing? Please select one option(1,2, or 3):
echo 1. Main Board w/ 6-Station OpCon.
echo 2. Main Board w/ 12-Station Opcon.
echo 3. OpCon Board.
set /P INPUT=Type input: %=%
If "%INPUT%"=="1" goto Option1
If "%INPUT%"=="2" goto Option2
If "%INPUT%"=="3" goto Option3
::::::::::::
:Option1
echo Starting 6-Station DFU flash...
echo xcopy "%~dp0M1k_MainPCB\6-STATION\*.*" "%drive%\Desktop\MainPCB6\" /d /s /h /v /c /f /k /y
echo cmd /k "cd /d %drive%\Desktop\MainPCB6\6-STATION\Debug\"
goto End
::::::::::::
:Option2
echo Starting 12-Station DFU flash...
echo xcopy "%~dp0M1k_MainPCB\12-STATION\*.*" "%drive%\Desktop\MainPCB12\" /d /s /h /v /c /f /k /y
echo cmd /k "cd /d %drive%\Desktop\MainPCB12\12-STATION\Debug\"
goto End
::::::::::::
:Option3
echo Starting OpCon DFU flash...
xcopy "%~dp0M1k_SWPCB\SWPCB\*.*" "%drive%\Desktop\SWPCB\" /d /s /h /v /c /f /k /y
cmd /k "cd /d %drive%\Desktop\SWPCB\SWPCB\Debug\"
::batchisp -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0
goto End
::::::::::::
:End
echo ******
echo *****
echo ****
echo ***
echo **
echo *
echo Flash Completed! Press any key to exit...
Pause>NUL&Exit
非常感谢任何帮助。
谢谢
答案 0 :(得分:2)
您正在更改CMD(CMD / K)的新实例中的工作目录,使用PUSHD更改当前CMD实例中的工作目录,使用POPD返回上次使用的目录:
@Echo OFF
PUSHD %WINDIR%"
Echo I'm on "%CD%" Directory!
POPD
Echo I'm on "%CD%" Directory!
Pause&Exit
将您的代码更改为:
:Option3
echo Starting OpCon DFU flash...
xcopy "%~dp0M1k_SWPCB\SWPCB\*.*" "%drive%\Desktop\SWPCB\" /d /s /h /v /c /f /k /y
PUSHD "%drive%\Desktop\SWPCB\SWPCB\Debug"
batchisp -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0
POPD
goto :End
...或者,如果您想直接在新的CMD实例中启动命令,请将其更改为:
CMD /k "Start /W """" "%drive%\Desktop\SWPCB\SWPCB\Debug\batchisp" -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0"
PS:请记住,您不需要更改工作目录来启动应用程序,您可以像上一个例子一样编写流程名称后跟的路径。