Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
Otterscript: Usage of Success exit code or EXEC operation - clarifications
-
Hi Alana,
Are you planning on adding a return value for an Exec operation? In my job, I call an otter script which calls pwsh via Exec and would like to send an email based on its return (success\failure).Thanks!
Scott -
Hi @scusson_9923 ,
Exec(orExecute-Process) runs an operating system process, so that's where the return code comes in.If you're doing something like a
PSCall, then you can create output parameters/variables in the script, and then test those values.-- Dean
-
@dean-houston Hi Dean,
I am having a difficult time understanding the workflow here.
As an experiment, I run a ps1 which sets $Fail to "true" as an Ad Hoc job:
InedoCore::Exec ( FileName: pwsh, WorkingDirectory: C:\, Arguments: test.ps1, ErrorOutputLogLevel: Error, OutputLogLevel: Information, SuccessExitCode: == 0 ); if $Fail == "true" { InedoCore::Send-Email ( ... ); }I get this: Could not resolve variable $Fail.
Do you have a working example? I must be missing something.
Also, what is the purpose of SuccessExitCode if you cannot test on it?
Thanks!
Scott -
Hi @scusson_9923 ,
Sorry, I misunderstood; I thought you were doing
PSExec.In this case you are just executing the
pwshprocess, so you need to figure out how to have that process return an exit code.I don't know if that's the same as
powershell.exe, but a AI told me "To return an error code from a PowerShell script, theexitstatement followed by the desired error code should be used."So I guess
exit -1or something like that?-- Dean
-
@dean-houston Hi Dean,
I did try setting the return of my PowerShell test script to exit -1 which fails the InedoCore::Exec call as expected. I just need to capture that failure and test on it.
Thanks,
Scott -
Any updates on this?
Thanks!
Scott -
Hi @scusson_9923 ,
Can you clarify what update you're looking for?
Are you looking for help on how to capture a failure and test on it?
Thanks,
Alana -
Hi Alana,
What I am trying to do is capture the result (success or fail) of this call:
InedoCore::Exec ( FileName: pwsh, WorkingDirectory: C:\, Arguments: test.ps1, ErrorOutputLogLevel: Error, OutputLogLevel: Information, SuccessExitCode: == 0 );My understanding is that currently InedoCore::Exec does not have a return value. I was hoping for something like:
$ret = InedoCore::Exec ( ... ); if $ret == "0" { // do operations for success } else { // do operations for failure }Thanks!
Scott -
Hi @scusson_9923 ,
Thanks for clarifying. You're right, the result is not available as a variable. Instead, the Operation will fail, which means you'd want to handle this via a try/catch.
try { InedoCore::Exec ( FileName: pwsh, WorkingDirectory: C:\, Arguments: test.ps1, ErrorOutputLogLevel: Error, OutputLogLevel: Information, SuccessExitCode: == 0 ); ... operations for success... } catch { ... operations upon failure ... }Hope that helps,
Alana -
Hi Alana,
This seems to work for what I am trying to accomplish.
Thanks!
Scott
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login