Expanding variables in a Windows batch file

不羁的心 提交于 2020-01-17 08:14:00

问题


I run the following command in a Windows batch file:

start "" "C:\PDF Viewer\PDFXCview.exe" /A "page=1&zoom=33.3" "G:\my pdfs\file 1.pdf" /A "page=4&zoom=55.5" "G:\my pdfs\file 2.pdf"

The works perfectly fine and opens both PDF files using their respective parameters. However, to make the process cleaner, I would like to start using variables in place of the PDF files (and even the PDF viewer executable). However, when I use variables, only the first PDF file opens:

set PDF1="G:\my pdfs\file 1.pdf"
set PDF2="G:\my pdfs\file 2.pdf"
start "" "C:\PDF Viewer\PDFXCview.exe" /A "page=1&zoom=33.3" %PDF1% /A "page=4&zoom=55.5" %PDF2%

I should mention that I don't have this issue if I remove the /A command and the subsequent parameters for each file.


回答1:


Wrong quotation in set commands. Use set "variable=value" syntax as follows:

set "PDF1=G:\my pdfs\file 1.pdf"
set "PDF2=G:\my pdfs\file 2.pdf"
start "" "C:\PDF Viewer\PDFXCview.exe" /A "page=1&zoom=33.3" "%PDF1%" /A "page=4&zoom=55.5" "%PDF2%"


来源:https://stackoverflow.com/questions/28775849/expanding-variables-in-a-windows-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!