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%&pause
----------------------------------------------------------------------------------
@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]]
本文转自leonardos51CTO博客,原文链接:http://blog.51cto.com/leomars/632012 ,如需转载请自行联系原作者