# Starting a process and sending subsequent commands using Process library

**URL:** <https://forum.robotframework.org/t/starting-a-process-and-sending-subsequent-commands-using-process-library/7848>\
**Category:** Libraries\
**Created:** [26 September 2024 18:16 UTC](https://forum.robotframework.org/t/starting-a-process-and-sending-subsequent-commands-using-process-library/7848 "2024-09-26T18:16:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacobo1451](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jacobo1451](https://forum.robotframework.org/u/Jacobo1451)\
**Post date:** [26 September 2024 18:16 UTC](https://forum.robotframework.org/t/starting-a-process-and-sending-subsequent-commands-using-process-library/7848/1 "2024-09-26T18:16:50Z")

</div>

Hello.  
I am writing a test that interacts with a python script, the most straightforward use case would be to start the python script via process, show a prompt expecting input and send additional commands, then expect another prompt and again send commands. Doing that until the process exits manually or finishes.

To do so I am intending to start a process and send additional commands to the stdin of the started process.  
I can start it, however I don´t seem to be able to send the next commands.

This is just a simple example of what it could look like.

#mockup\_test.robot  
${SCRIPT\_PROCESS}= Start Process python ${SCRIPT\_PATH} stdout=PIPE

${result}= Run Process exit stdin=${SCRIPT\_PROCESS.stdout}

#mockup\_python\_script.py

import time  
import sys

def simulate\_device\_action():  
“”“Simulates a device action and returns a status code.”“”  
import random  
status\_codes = [“200”, “404”, “500”]  
return random.choice(status\_codes)

def main():  
# Check if maintenance mode is enabled  
if “–maintenance-mode” in sys.argv:  
print(“Script started in maintenance mode”)

```
# Simulate listening for commands
while True:
    try:
        command = input("Awaiting command: ")
        if command == "exit":
            print("Exiting script...")
            break
        elif command == "continue":
            print(f"Processing command: {command}")
            time.sleep(1)
            print("Command executed successfully.")
        else:
            print(f"Received unknown command: {command}")
            print(f"Simulating action...")
            time.sleep(1)
            status = simulate_device_action()
            print(f"Action completed with status: {status}")
    except KeyboardInterrupt:
        print("\nScript interrupted by user.")
        break

```

if **name** == “ **main** ”:  
main()

Can someone help me figuring out what is the most straightforward way to achieve this?

Thanks.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [26 September 2024 19:25 UTC](https://forum.robotframework.org/t/starting-a-process-and-sending-subsequent-commands-using-process-library/7848/2 "2024-09-26T19:25:53Z")

</div>

Try to learn about the `subprocess` module. Although the examples are for external commands, [this link](https://realpython.com/python-subprocess/), you can use for your goals.

See the official docs of `subprocess` [here](https://docs.python.org/3/library/subprocess.html).

[Here](https://docs.python.org/3/library/asyncio.html#module-asyncio) in `asyncio` module there is more information.

Maybe you can also see `threading`, [here](https://docs.python.org/3/library/threading.html).
