2015-09-16 1 views
0

Что мне здесь не хватает?Сценарий PowerShell - Преобразование PDF-файлов в TIF с использованием Ghostscript

Я получаю эту ошибку:

ERROR converting File 
E:\DocuTA\TIFs\06fef98e-e1c5-405e-93ea-c684ee7a856d.tif 
nvoke-Expression : You must provide a value expression on the 
right-hand side of the '-' operator. At E:\DocuTA\ConvPDFtoTIF.ps1:31 
char:26 + $ret = invoke-expression <<<< -command $cmdline + 
CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException + 
FullyQualifiedErrorId : 
ExpectedValueExpression,Microsoft.PowerShell.Commands.InvokeExpressionCommand 

при выполнении этого сценария:

#recursively crawls the directory tree and converts pdf files to tif files 
#compresses the images to a smaller file size. 

$Now = get-date 
$Days = "14" 
$LastWrite = $Now.AddDays(-$Days) 
$srcfolder = "E:\DocuTA\PDFs\" 
$destfolder = "E:\DocuTA\TIFs\" 
$convert = "& C:\Program Files (x86)\gs\gs9.16\bin\gswin32c.exe" 
$filter = "*.pdf" 
$dest_ext = "tif" 
$arg1 = @(" -dNOPAUSE -dQUIET -r300x300 -sDEVICE=tiffg4 -dBATCH ") 
$lfpath = "E:\DocuTA\Logs\" 
$logfile = new-item -type file -name "PDF2TIFLog$(get-date -uformat '%Y%m%d%H%M%S').log" -path "$lfpath" 
$elogfile = "E:\DocuTA\Logs\PDF2TIFErrorLog.log" 
#------------------------------------------------------------------- 
$count = 0 
Write-Output "`nStarting ... ($Now)" | Out-File -Append $logfile 
Try 
{ 
foreach ($srcitem in $(Get-ChildItem $srcfolder -Include $filter -Recurse | Where-Object {$_.LastWriteTime -gt "$LastWrite"})) 
{ 
$count++ 
$srcname = $srcitem.FullName 
$partial = $srcitem.FullName.Substring($srcfolder.Length) 
$destname = $destfolder+$partial 
$destname = [System.IO.Path]::ChangeExtension($destname,$dest_ext) 
$destpath = [System.IO.Path]::GetDirectoryName($destname) 
$cmdline = "'"+$convert+"'"+"'"+$srcname+"'"+$arg1+ "'"+$destname+"'" 
Write-Output "[$count] $cmdline" | Out-File -Append $logfile 
$ret = invoke-expression -command $cmdline 
Write-Output "[$count] OUTPUT: $ret" | Out-File -Append $logfile 
Write-Output "[$count] processed file." | Out-File -Append $logfile 
} 
} 
Catch 
{ 
$Now | out-file -Append $elogfile 
write-output "ERROR converting File $destname" | out-file -Append $elogfile 
Write-Output $Error[0] | out-file -Append $elogfile 
} 
Finally 
{ 
Write-Output "Finished processing files. Total: $count`n" | Out-File -Append $logfile 
} 

ответ

0

Похоже PowerShell не нравится использовать - для выключателей, попробуйте использовать вместо #

+0

Если Я запускаю из командной строки Windows, чтобы получить подсказку для каждой страницы. «C: \ Program Files (x86) \ gs \ gs9.16 \ bin \ gswin32c.exe" "E: \ DocuTA \ PDFs \ 06fef98e-e1c5-405e-93ea-c684ee7a856d.pdf" -dNOPAUSE -dQUIET -r300x300 -sDEVICE = tiffg4 -dNOPROMPT -dBATCH "E: \ DocuTA \ TIFs \ 06fef98e-e1c5-405e-93ea-c684ee7a856d.tif" обработки страницы 1 до 99. Page 1 Загрузка NimbusSan-Бол шрифт из % ром % Ресурс/Шрифт/NimbusSan-Bol ... 3866684 2360 085 8995292 7655146 3 сделано. Загрузка NimbusSan-Reg шрифт из % ПЗУ% Ресурс/Font/NimbusSan-Reg ... 3899796 2450 968 9035492 7692024 3 сделано. >> showpage, нажмите, чтобы продолжить << – user5305155

+0

Вы поместили входной файл перед коммутаторами, поэтому он будет обрабатывать это, прежде чем читать оставшуюся часть командной строки. Поместите файл ввода последним. – KenS

+0

Я обновил следующее ниже, и теперь он работает. $ cmdline = "" "$ convert" "" + $ arg1 + "" "$ destname" "" + "" + "" "$ srcname" "" $ ret = invoke-expression -command "& $ cmdline" – user5305155