mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* initialize control loop * add todo * more todo * add dockerignore * add notes to prompt * encourage llm to finish * add debug env * update prompts a bit * fix task prompts * add basic regression framework * add hello-world regression case * add hello-name test case * fix workspace ignore * document regression script * add python-cli test case * add default git config * add help regression test * add node rewrite test case * add react-todo test case * fix dockerfile * add ability to run background commands * add client-server test case * update regression readme * better support for background commands * update tests * fix bug in command removal
19 lines
737 B
Python
19 lines
737 B
Python
import subprocess
|
|
import os
|
|
|
|
def run(cmd, agent, background=False):
|
|
if background:
|
|
return run_background(cmd, agent)
|
|
result = subprocess.run(["/bin/bash", "-c", cmd], capture_output=True, text=True)
|
|
output = result.stdout + result.stderr
|
|
exit_code = result.returncode
|
|
if exit_code != 0:
|
|
raise ValueError('Command failed with exit code ' + str(exit_code) + ': ' + output)
|
|
return output
|
|
|
|
def run_background(cmd, agent):
|
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
|
|
agent.background_commands.append(process)
|
|
return "Background command started. To stop it, send a `kill` action with id " + str(len(agent.background_commands) - 1)
|
|
|