Get output value from process when run through Powershell

Hi,

Here’s my situation :

  • I have a python file that is my starting point
  • In this .py file, I’m iterating through an Excel file
  • For each row, I use subprocess.run() to run an automation with arguments
  • The .py file knows to wait for each UiPath process to end before running another

Here’s my question :

  • In case the UiPath process fails (due to some unexpected behaviour), how can the python script know it failed ?

Here’s my thought :

  • I understand using subprocess.run() results in using PowerShell, so I guess I need to save the output of the python method to filter the result

Here’s another question in that case :

  • How can the UiPath process return a value in the PowerShell that ran it ? Is there like an output value for the whole process ?

Thanks for any answer !

@PythonDev85

  1. Use a try catch in your UiPath bot and write the exception ir failed message some where or pass to python…so that even when failed still process closes smoothly and pythongets control
  2. For power shell you can use this …this has output as well
    PowerShell and UiPath - "Invoke PowerShell" Tutorial | UiPath

Cheers

1 Like

Hi @PythonDev85

You can try to capture the output of the PowerShell command that launches the UiPath process using subprocess.run() in Python. The subprocess.run() method returns a CompletedProcess object that has attributes like returncode and stdout that you can use to check if the process completed successfully or not.

To have the UiPath process return a value that can be captured by the PowerShell script, you can use the Write-Output cmdlet in PowerShell.

Thanks!!

1 Like

Thanks for the answer.

I can’t use #2 because I don’t call any Power Shell window into my UiPath process

For #1, this is what I thought and it works. Though it’s not the result I want, because I don’t only want to know when it crashes, but I want to know it’s status (since my process ends on different conditions, depending if a file has already been done or not).
To be clear on what my process does : It logs on to an app, tries to click a button that does something with a client folder. If the folder has already been treated by a co-worker, then it end. If it has not been treated, it tries to click the button. If the button gives an error, it does a loop to change folder setting before trying again. So I have a routine in case of some result. And my runs would return either “Crash”,“Done”,“Already done”. That’s more like something I would’ve wanted. Mostly like getting “checkpoint flags”

I still ran my process anyway because it’s just a process control system, nothing too important right now. But for later cases, I would want to get that info, and I think the only way is to output the “checkpoints” onto an external data file.

Thanks anyway for your answer :slight_smile:

Thanks for the answer.

I got aware of the CompletedProcess object, and it currently catches something if the process crashes and returns it in CompletedProcess.stderr. Though for any other output, I don’t get anything in CompletedProcess.stdout.
I tried using either “Write Line” or “Log Message” activity on different levels, and nothing works (even Error or Fatal levels). I also tried using an Out Argument that could’ve appeared at the end of the process, but nothing

I’m sure it’s close to a result with the CompletedProcess object, but I can’t figure out why I get crashes messages but nothing else…

I’m gonna try the “Write-Output” cmdlet as another subprocess call before running the activities. I hope it keeps the same Powershell process for that !

Thanks anyway for your answer :slight_smile:

1 Like

@PythonDev85

Then you can write the status to a file from python and reqd yhe same file in UiPath to know the status

Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.