簡體   English   中英

在批處理文件中使用變量存儲命令然后執行

[英]Using a variable in batch file to store a command then execute it

我是批處理文件的新手。 基本上我需要做的是這樣的

if %1==choice1 set command=dir if %1==choice2 set command=rmdir %command% /q /s

有任何想法嗎?

您的問題不清楚您需要什么。 請更具體。 要將輸入保存命令與變量進行比較,請使用:

if "%1"=="choice1" set "command=dir" 
if "%1"=="choice2" set "command=rmdir /q /s PATH_TO_DELETE" 

要稍后運行命令,只需使用:

%command%

我強烈建議您在變量名上放置一個唯一的標識符,例如my_saved_command,而不要單獨使用諸如command這樣的常用詞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM