I am trying to use cleartool command in powershell.
If the command fails, it should catch the exception and do the action. But it was not caught by catch {}
try {
#If $viewname not exist it will throw error
cleartool lsview $ViewName
}
catch {
# If list view fails , it means View doesn't exist. So create view
Write-host "Create view"
cleartool mkview -tag $ViewName -nsh $ccViews$ViewName".vws"
}
When commands in try fails , it doesn't invoke expressions in catch.
Whether catch command won't work with non .net related stuff?
I never saw the exception mechanism used in powershell script for cleartool.
(The couple I saw were in "how to find root[folder] for each component using cleartool?", and in "How to describe recommend baseline with pipeline").
This old thread (2006, so for the first version of Powershell) illustrates that error management mechanism using $?
:
cleartool lsco -cview -s . |
foreach {
cleartool diff -pred -opt -sta "$_"
if ($?) {
cleartool unco -rm "$_"
} else {
cleartool ci -nc "$_"
}
}
To use your mechanism, you might want to encapsulate your cleartool call in an Invoke-Command, and return a status code from the wrapper function, as described in "catching return code of a command with “invoke-command
” - Powershell 2".
Or, instead of calling directly cleartool, you can try an call the CAL commands as in this script.