Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    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

    Scheduled Pinned Locked Moved Support
    12 Posts 4 Posters 63 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      scusson_9923
      last edited by

      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

      dean-houstonD 1 Reply Last reply Reply Quote 0
      • dean-houstonD Offline
        dean-houston inedo-engineer @scusson_9923
        last edited by

        Hi @scusson_9923 ,

        Exec (or Execute-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

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          scusson_9923 @dean-houston
          last edited by apxltd

          @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

          dean-houstonD 1 Reply Last reply Reply Quote 0
          • dean-houstonD Offline
            dean-houston inedo-engineer @scusson_9923
            last edited by

            Hi @scusson_9923 ,

            Sorry, I misunderstood; I thought you were doing PSExec.

            In this case you are just executing the pwsh process, 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, the exit statement followed by the desired error code should be used."

            So I guess exit -1 or something like that?

            -- Dean

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              scusson_9923 @dean-houston
              last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • S Offline
                scusson_9923
                last edited by

                Any updates on this?

                Thanks!
                Scott

                atrippA 1 Reply Last reply Reply Quote 0
                • atrippA Offline
                  atripp inedo-engineer @scusson_9923
                  last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    scusson_9923
                    last edited by atripp

                    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

                    atrippA 1 Reply Last reply Reply Quote 0
                    • atrippA Offline
                      atripp inedo-engineer @scusson_9923
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        scusson_9923
                        last edited by

                        Hi Alana,

                        This seems to work for what I am trying to accomplish.

                        Thanks!

                        Scott

                        1 Reply Last reply Reply Quote 0

                        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
                        • 1 / 1
                        • First post
                          Last post
                        Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation