Question

How to return an Exit Code from a powershell script that has been called by a batch file.

  • 28 February 2022
  • 2 replies
  • 842 views

Badge +3

Using the Application: Open program/file command

I fill in the 

Location of the program/file 

and

Parameters

for a batch file.

 

The batch file then calls a powershell file. 

I need to modify the powershell file to return an error code.

Then I need the returned error code from the powershell to be passed to the batch file. 

Then in the bot, add an IF command to see if the error code exists. 

 

Is this something that can be done in Automation Anywhere?

If so can someone please let me know how it can be done?

 

  1. Task bot calls batch file.
  2. Batch file calls powershell file.
  3. Powershell file returns exit code to batch file.
  4. Task bot uses exit code from batch file to make decisions.

 

I currently have the batch file and the powershell file working but the powershell isn't returning an exit code.

There doesn't seem to be a way for the batch file to accept a return code.

I'm pretty sure I can figure out how to write the return code in the powershell but am not sure if it can be handled in the batch file and the taskbot.


2 replies

Userlevel 7
Badge +10

Hello Eddie,

 

I request you to please try as below:-

 

>Once PowerShell is executed, copy the exit code in a notepad.

>Now use 'Get text' command from Automation Anywhere to get the text in the variable.

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/using-get-text-action.html/p>

>Now you can use the same variable in your bot to view the information.

 

If you have any questions please let me know.

 

Automation Anywhere,

Prabhakar Jha

Badge +3

Thank you Prabakar. That is essentially what I'm doing. I've had some issues with GetText action and had to read the file via notepad. Your solution works. I just wish there was a more direct way of returning data to the bot instead of writing things to a file. I appreciate your input.

Reply