将参数传递给应用程序 [英] Pass parameters to an application
问题描述
我正在尝试使用ghostscript为扫描的PDF文件设置特定的页面大小。当脚本与可执行文件位于同一文件夹时,我可以运行该脚本,但是当我将.vbs文件移出目录时,我无法使其运行。 .run行是我遇到问题的地方。没有参数的exe路径的三引号会打开exe,但我不知道如何传递参数。
我确定您可以看到我对此很陌生。
I'm attempting to use ghostscript to set a specific page size for scanned PDF files. I can run the script when it resides in the same folder as the executable but when I move the .vbs file out of the directory I can't get it to work. The .run line is where I'm having problems. The triple quotes for exe path without arguments opens the exe but i can't figure out how to pass the parameters. I'm sure you can see that I'm pretty new to this.
strInput = InputBox ("Enter 1 for Landscape or 2 for portrait:")
Set objShell = WScript.CreateObject("WScript.Shell")
If strInput=1 then
Call LandScape
ElseIf strInput=2 Then
Call Portrait
Else
MsgBox "Your entry is invalid. Click OK to exit"
End If
Landscape子例程:
Landscape sub-routine:
Sub LandScape
MsgBox "Your images are Landscape"
objShell.Run """c:\Program Files\gs\gs9.04\bin\gswin64c.exe""& "-dQUIET"&" -dNOPAUSE"&" -dBATCH"&" -dDEVICEWIDTHPOINTS=2592"&" -dDEVICEHEIGHTPOINTS=1728"&" -dFIXEDMEDIA"&" -sDEVICE=pdfwrite"&" -sOutputFile=OUTPUT.pdf"&" INPUT.pdf""
'This line works when in same directory: gswin64c -dQUIET -dNOPAUSE -dBATCH -dDEVICEWIDTHPOINTS=2592 -dDEVICEHEIGHTPOINTS=1728 -dFIXEDMEDIA -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf INPUT.pdf
End Sub
推荐答案
引号可以变得令人困惑,因此有时可以使用 Chr(34)
代替,并使可执行文件与其参数分开。
The quotes can get confusing so it sometimes helps to use Chr(34)
instead and to keep the executable separate from its params.
strExe = "c:\Program Files\gs\gs9.04\bin\gswin64c.exe"
strParams = "-dQUIET -dNOPAUSE -dBATCH -dDEVICEWIDTHPOINTS=2592 -dDEVICEHEIGHTPOINTS=1728 -dFIXEDMEDIA -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf INPUT.pdf"
objShell.Run Chr(34) & strExe & Chr(34) & " " & strParams
这篇关于将参数传递给应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!