我有一个非常简单的批处理文件,它运行SQL查询文件并将结果复制到打印机。即使查询结果为0行,也会打印问题。如果有数据,我怎么才能打印?批处理文件中的条件打印
cd stock
sqlcmd -i testquery.sql -S localhost -U User -P password -o testresults.txt
copy testresults.txt \\printserver\share
sqlcmd -i ems_update.sql -S localhost -U User -P password
del c:\stock\testresults.txt
exit
好吧,这是我现在有:
cd c:\stock
sqlcmd -i testquery.sql -S localhost -U User -P password -o testresults.txt
@find /c /i "0 rows" "C:\stock\testresults.txt" > NUL
if %ERRORLEVEL% EQU 1 (
pause
) else (
copy c:\stock\testresults.txt \\printserver\share)
pause
sqlcmd -i ems_update.sql -S localhost -U User -P password
我不能复制命令立即执行。我在想什么? 感谢
批'if'比较仅检查字符串值,以便'if'语句在100%的时间内为假。批量中的变量也被称为'%this%'。 – SomethingDark
'set var_name = type contents.txt'将生成一个包含文件内容的字符串。 – MotKohn
不,你需要一个'for'循环来处理命令的输出。 'for/f“delims =”%% A in('type contents.txt')do set var_name = %% A'会将变量设置为文件的内容。 – SomethingDark