我需要在 powershell 脚本中调用可执行文件并希望等待其结果。对于这个exe,我需要提供一些包含在我的变量中的参数,但这不起作用
$gs = $currentPath +"\gs\gs8.70\bin\gswin32c.exe";
$outPdf="$cachepath\foobar_$IID.pdf"
$PS_FILE = "$cachepath\$IID.pdf"
我尝试像这样调用 gswin32c.exe
& $gs q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outPdf $PS_FILE
但这会导致错误
gswin32c.exe : GPL Ghostscript 8.70: Unrecoverable error, exit code 1
In F:\pdix-services\GWT-BPS\EventHandler\adobe-printing.ps1:21 Zeichen:1
+ & $gs q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outPdf $PS_FIL ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (GPL Ghostscript...or, exit code 1:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
我认为可能会出现错误,因为我需要将参数放在引号中,但正确的参数是什么?我的测试没有成功。
thanks
您应该能够这样编写命令:
& $gs q "-dSAFER" "-dNOPAUSE" "-dBATCH" "-sDEVICE=pdfwrite" "-sOutputFile=$outPDF"
我写了一篇关于此的文章可能会有所帮助:
Windows IT 专业人士:在 PowerShell 中运行可执行文件 http://windowsitpro.com/powershell/running-executables-powershell
The showargs.exe
本文下载中提供的实用程序有助于解决 PowerShell 命令行解析问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)