2種方法
A:
@echo off
hostname>a.txt
set /p a=<a.txt
echo %a%
B:
命令行
for /f "delims=" %a in ('hostname') do set myvar=%a
echo %myvar%&pause
在批處理中
for /f "delims=" %%a in ('hostname') do set myvar=%%a
echo %myvar%&pausespring
----------------------------------------------------------------------------------app
@echo off
for /f "delims=" %%a in ('date1 -d "1 days ago" +%%Y.%%m.%%d') do set myvar=%%a
rar a D:\AutoBackup\app_log\log4net\springlings-170.15-%myvar%.rar D:\log4net\springairlines\%myvar%
net use \\192.168.170.12 /user:administrator sss2kadmin
copy D:\AutoBackup\app_log\log4net\springlings-170.15-%myvar%.rar \\192.168.170.12\ha_hfs\170.15
ide