将参数传递给应用程序

编程入门 行业动态 更新时间:2024-10-25 23:21:13
本文介绍了将参数传递给应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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

更多推荐

将参数传递给应用程序

本文发布于:2023-11-16 07:45:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602343.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!