我想獲得正確的錯誤消息,它在描述中。但是當我的調試器進入substring
行時,它沒有理由退出。提取一個子字符串
$job= submitting the job 2fdab2d5-f09c-4392-953e-8b85f90d76eb ...
client version: 10.2.2.0
target: cluster
stat: simulatelarge
skippath: true error submitting job.
vcclientexceptions.vcclientexception: [httpstatuscode = 0; description = e_csc_user_syntaxerror: syntax error. expected one of:_all _and ';' ')' ','
description: invalid syntax found in the script.
resolution: correct the script syntax, using expected token(s) as a guide.... at token [output], line 13 near the ###:
$descpos = $job.IndexOf("description:")
$resopos = $job.IndexOf("resolution:")
$descmsg = $descmsg.Substring($descpos)
Write-Host $descmsg
$ferrormsg = $job.Substring($msgpos,$respos+1)
Write-Host $ferrormsg
工作 - CODE:
[string]$Result=$job
$Result= $Result -Replace "[\{]|(\{)|[\}]|(\})|[\""]|(\"")",''
$msgpos = $Result.IndexOf(("message:"))
$resopos = $Result.IndexOf(("resolution:"))
$descpos = $Result.IndexOf(("description:"))
$ferrormsg = $Result.Substring($msgpos,($descpos-$msgpos))
$ferrormsg = $ferrormsg -Replace "(\,)|(\')|(\-)|(\=)",''
Write-Host $ferrormsg
感謝所有, 保換我的字符串是工作的罰款。
是'$ job'字符串數組或用換行一個字符串? – vonPryz
'$ job =提交工作2fdab2d5-f09c-4392-953e-8b85f90d76eb ...'會拋出一個'CommandNotFoundException' – Clijsters
沒有它的一個字符串整個 –