# How to output "Fail" when a testing script returns exit code(1)?

**URL:** <https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719>\
**Category:** Robot Framework\
**Created:** [20 August 2024 09:43 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719 "2024-08-20T09:43:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fon1105](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fon1105/32/4149_2.png) [@fon1105](https://forum.robotframework.org/u/fon1105)\
**Post date:** [20 August 2024 09:43 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719/1 "2024-08-20T09:43:36Z")

</div>

\*\*\* Settings \*\*\*  
Documentation Stream

Library Stream.py

\*\*\* Test Cases \*\*\*  
Play Stream  
Stream

\*\*\* Keywords \*\*\*  
Stream  
play item=rtsp

The script(Stream.py) will return exit code(1) when encountering fail case.  
However, the robot framework will stop testing(no report generated) instead of showing “Fail” when getting the exit code(1) from the script.

What should I do so that the robot framework can output “Fail” when the script return exit code(1)?

OS: Windows 11  
Python: 3.12.0  
Robotframework: 7.0.1

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [20 August 2024 11:04 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719/2 "2024-08-20T11:04:56Z")

</div>

Hi,

From your description, the .py script throw an exception with code (1), so of course as error is in the script RF stops.  
You should use a Try/Expect in your .py to catch this exception, then return something to RF.  
Then when calling your script as keyword you can use a variable to get return code and use Fail keyword to stop test. Something like this:

```
***Keywords***
Stream
   ${statuscode} play item=rtsp
   IF ${statuscode} == 1 Fail msg=yourmessage

```

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![fon1105](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fon1105/32/4149_2.png) [@fon1105](https://forum.robotframework.org/u/fon1105)\
**Post date:** [20 August 2024 11:14 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719/3 "2024-08-20T11:14:31Z")

</div>

Hello,

Thank you for your reply.  
Due to unexpected problem, the script will output another exit code: Process finished with exit code -1073740791 (0xC0000409) when I manually raise an exception in the .py script.

That’s why I must use “sys.exit(1)” to output the return code(1) when encountering a fail case.

Is there any way that I can avoid RF stop and it can output Fail in the situation? Thanks.

---

<div class="post-metadata">

**Author:** ![FrancisG](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/francisg/32/4247_2.png) [@FrancisG](https://forum.robotframework.org/u/FrancisG)\
**Post date:** [20 August 2024 11:44 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719/4 "2024-08-20T11:44:24Z")

</div>

What about using the [Process library](https://robotframework.org/robotframework/latest/libraries/Process.html) to run your test script? Rather than importing your script as a library.

With _Run Process_ you can get the script stdout, stderr and return code. See [example](https://robotframework.org/robotframework/latest/libraries/Process.html#Example).

---

<div class="post-metadata">

**Author:** ![fon1105](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fon1105/32/4149_2.png) [@fon1105](https://forum.robotframework.org/u/fon1105)\
**Post date:** [21 August 2024 03:02 UTC](https://forum.robotframework.org/t/how-to-output-fail-when-a-testing-script-returns-exit-code-1/7719/5 "2024-08-21T03:02:18Z")

</div>

Hello @FrancisG,

Thank you for your advise. I got it working with process library.
