我有一个bat脚本,要求用户输入下一行
SET /P returnString=Enter string: %=%
现在我希望默认输入在命令行上可见,例如:
Enter string: defaultstring
澄清一下:如果没有给出输入,我不需要默认值,我希望默认值在命令行上可见且可编辑,因此在上述情况下,defaultstring
可以是替换为不同的文本。
这可以通过批处理文件中的 SET 实现吗?如果没有,我怎样才能做到这一点?
最佳答案
这是一个 Batch + JScript 混合脚本,它会提示默认值。
@if (@CodeSection == @Batch) @then
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The first line in the script is...
:: in Batch, a valid IF command that does nothing.
:: in JScript, a conditional compilation IF statement that is false.
:: So the following section is omitted until the next "[at]end".
:: Note: the "[at]then" is required for Batch to prevent a syntax error.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Batch Section
@echo off
setlocal
set "Input="
set "Default=Hello World"
title MyUniqueTitle
CScript //E:JScript //Nologo "%~f0" "MyUniqueTitle" "%Default%"
set /p "Input=> Prompt: "
if defined Input set "Input=%Input:"=%"
echo(%Input%
endlocal
exit /b 0
:: End of Batch
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@end
////////////////////////////////////////////////////////////////////////////////
// JScript Section
try
{
var WshShell = WScript.CreateObject('WScript.Shell');
var Title = WScript.Arguments.Item(0);
var Message = WScript.Arguments.Item(1);
WshShell.AppActivate(Title);
WshShell.SendKeys(Message);
WScript.Quit(0);
}
catch(e)
{
WScript.Echo(e);
WScript.Quit(1);
}
WScript.Quit(2);
关于windows - 使用 bat 文件在命令提示符中放置可编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22307919/