Word 문서를 텍스트로 변환하지만 Null 유형 오류가 발생하는 Jenkins 플러그인을 통해 PowerShell 스크립트를 실행하려고합니다. 슬레이브는 Win 2008 박스이고 Jenkins는 서비스로 실행 중이며 서비스는 관리자로 실행 중입니다. 내가 시도 :Jenkins PowerShell Plugin - Returning Null
- 명령이 로컬로 실행하여 원격 상자에서 작동하는지 확인.
- Windows 배치 (동일한 오류)를 사용하여 PowerShell 스크립트를 실행합니다.
- 젠킨스 플러그인을 통해 명령을 실행합니다. (
$Doc
NULL로 설정되는)
스크립트 :
$Files = Get-ChildItem 'PTX*.docx'
$Files
$Word = New-Object -ComObject Word.Application
$Word
foreach ($File in $Files) {
# open document in Word
$File.FullName
$Doc = $Word.Documents.Open($File.FullName)
$Doc
Start-Sleep -s 10
# swap out RTF for TXT in the filename
#$Name = ($Doc.FullName).Replace("docx", "txt")
#$Doc.SaveAs([ref] $Name, [ref] 2)
$Doc.Close()
}
가) 파일이 있었다와 b) 내가 Word 개체를 가지고 그 것을 확인했다. 다시 말하지만,이 모든 것은 원격 상자에서 잘 작동합니다.
$Word
$Doc
가 설정되지있어 않기 때문에
Application : Microsoft.Office.Interop.Word.ApplicationClass Creator : 1297307460 Parent : Microsoft.Office.Interop.Word.ApplicationClass Name : Microsoft Word Documents : System.__ComObject Windows : System.__ComObject ActiveDocument : . . .
오류는 주변에서 발생한다. 실행 중에 $Doc
을 인쇄하려고 시도했지만 아무 것도 표시되지 않았습니다.
C:\jenkins\workspace\eggplant-Test\DVA.docx You cannot call a method on a null-valued expression. At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson1097244472905940013.ps1:19 char:12 + $Doc.Close <<<<() + CategoryInfo : InvalidOperation: (close:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
업데이트 : 안드레아스 M 제안
변경된 스크립트로 :
Foreach ($File in $Files) {
# open document in Word
echo File: $File.fullname
$Error.Clear() # Clear all other errors
$Doc = $Word.Documents.Open($File.FullName)
echo "Error count:" $Error.Count # Dump number of errors
$Error # Dump errors
echo "Doc:" $Doc
같은 오류하지만 이상하게도는 Word.Doc.Open 호출에서보고 된 오류없이.
File:
C:\jenkins\workspace\eggplant-Test\DVA.docx
Error count:
0
Doc:
You cannot call a method on a null-valued expression.
At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson3349169014447704754.ps1:23 ch
ar:12
+ $Doc.close <<<<()
+ CategoryInfo : InvalidOperation: (close:String) [], RuntimeExce
ption
+ FullyQualifiedErrorId : InvokeMethodOnNull
오류 출력으로 초기 질문이 업데이트되었습니다. Jenkins가 사용하는 것과 동일한 사용자 이름/암호를 사용하여 원격 상자에 로그인했으며 문제없이 스크립트를 실행할 수 있습니다. – stackbacker
링크를 제공해 주셔서 감사합니다. 나는 내 자신이 그 방향으로 결코 보지 않았을 것이라고 99 % 확신한다. 그것은 DCOM 문제가 아니었지만, SysWow 디렉토리 (그 링크에서 언급)에 Desktop을 추가하여 고정 시켰습니다. 다시 - 감사합니다. – stackbacker
다행 이네. 천만에요. – Moerwald