Forum Discussion

DavidE's avatar
DavidE
Contributor
7 years ago
Solved

Getting PowerShell Return Code

I am having trouble getting the return code from a powershell script when I execute an external powershell script as a file.  I looked at the documentation linked here, but it wasn't much help in terms of getting me what I was looking for.

 

Anyone have a quick sample script (Preferably in VBScript, but I will take whatever) that does this?

  • Hi,

     

    It sounds like you might be trying to mock up a kind of async calback type scenario?

     

    If so, one way to trigger the request via your mock is to invoke a TestCase which makes the Request - for an example please see:

     

    http://community.smartbear.com/t5/SoapUI-Open-Source/How-to-simulate-an-asynchronous-web-service-with-mock-services/m-p/98348#M17494

     

    Of course you can also programatically make the SOAP call from your mock, heres an example of making a SOAP request programtically:

     

    http://community.smartbear.com/t5/SoapUI-Open-Source/How-to-get-parameter-of-SOAP-operation/m-p/99768#M17648

     

    Or something similar is shown here for programatically creating a REST call:

     

    community.smartbear.com/t5/SoapUI-Open-Source/How-to-create-REST-project-using-Groovy-script/m-p/99305#M17568

     

    One advantage of the first approach (triggering a TestCase) is that the Mock can dispatch its response before the callback SOAP request is made. 

     

    Hope this helps give you some ideas,

     

    Rupert

  • rupert_anderson's avatar
    rupert_anderson
    10 years ago

    Hi Abdelwahab,

     

    If this is your first task with SoapUI, then I would say your homework is going well, its seems you have picked things up quickly! :-)

     

    If you do get my book, I would love to hear how you found it, any good and bad points, could help me to improve. 

     

    Yes, a kind of routing - the basis of our discussion here is from a recipe in the book, the topic is how to test & mock a SOAP async callbacks. The replyTo is in reference to the WS-Addressing standard, and its value is taken from the request like you say.

     

    In the recipe, there is a SoapUI situation someting like:

    1. Client TestRequest to mock (passing ReplyTo and messageId)

    2. Mock responds with acknowledgement.

    3. Mock triggers callBack to address in ReplyTo (after some delay) 

    4. SOAP Mock Response TestStep recieves callback and runs Assertions

     

    Best Regards,

    Rup

     

     

5 Replies

    • DavidE's avatar
      DavidE
      Contributor

      There are no examples in that documentation on retrieving the exitcode of a powershell script.  I tried using the example that returns text and instead of this line:

       

      Set oExec = oShell.Exec("powershell -command Get-Process")

       

      I used this:

       

      Set oExec = oShell.Exec("powershell -file c:\script\script.ps1")

       

      But I did not get a return value.

      • shankar_r's avatar
        shankar_r
        Community Hero

        You can get return as like below in command line

         

        I hope below script will do the same trick in TestComplete

        Set oExec = oShell.Exec("powershell -file c:\script\script.ps1");
        Log.Message(oShell.Run("cmd echo %errorlevel%");