我想在DOS批次中得到这种结果:
==> Please enter your filename, formatted as
[user][PC_id] :
允许用户在“:”
之后输入文件名我尝试了很多组合,但我能用
获得最好的组合ECHO --^> Please enter your filename, formatted as
Set /P FILE=[user][PC_id] :
(“[”未显示)之前的空格
答案 0 :(得分:3)
Vista / Win7中引入的功能存在问题
当使用set/p
时,它会删除字符串前面的所有空白字符。
但在你的情况下,这很容易,因为你想要回应两行。
@echo off
setlocal EnableDelayedExpansion
set LF=^
set /p "file=--> Please enter your filename, formatted as!LF! [user][PC_id]"
答案 1 :(得分:2)
当您打印2行时,jeb的解决方案正常工作。但是,当您只想打印带有前导空格的单行时,有一个通用的解决方案。您只需要一个退格符。
@echo off
setlocal
:: Define BS to contain a backspace
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"
::Only need %BS% if you know prompt starts at line beginning
Set /P "FILE=%BS% [user][PC_id] : "
::If prompt is not at line beginning then need an extra char before %BS%
<nul set /p "=Part1"
<nul set /p "=.%BS% Part2"
答案 2 :(得分:2)
另一种变体:
exit | cmd /k prompt -$G Please enter your filename, formatted as$_$s$s$s[user][PC_id]$s
set /p FILE=
echo %FILE%