MCPcopy Create free account
hub / github.com/aitjcize/Overlord / RunCommand

Method RunCommand

py/ovl.py:795–826  ·  view source on GitHub ↗

Run `cmd` on the remote shell, streaming bytes to `writer`. Returns the command's exit code, or -1 if the shell died.

(self, cmd, writer)

Source from the content-addressed store, hash-verified

793 raise RuntimeError('persistent shell: WebSocket did not open')
794
795 def RunCommand(self, cmd, writer):
796 """Run `cmd` on the remote shell, streaming bytes to `writer`.
797
798 Returns the command's exit code, or -1 if the shell died.
799 """
800 self.WaitReady()
801 nonce = os.urandom(16).hex().encode()
802 with self._cmd_mutex:
803 with self._cv:
804 if self._died:
805 return -1
806 self._active_nonce = nonce
807 self._active_writer = writer
808 self._exit_code = None
809 self._buf = b''
810 # `$?` after `cmd` is the exit of `cmd`'s last statement, matching
811 # normal shell semantics (e.g. `cd a && make` -> make's exit).
812 wrapper = (cmd.encode() + b'\n' + b"printf '\\n__OVL_END_" + nonce +
813 b":%d\\n' \"$?\"\n")
814 try:
815 self.send(wrapper, binary=True)
816 except Exception:
817 with self._cv:
818 self._died = True
819 return -1
820 with self._cv:
821 while self._exit_code is None and not self._died:
822 self._cv.wait()
823 code = -1 if self._died and self._exit_code is None else self._exit_code
824 self._active_nonce = None
825 self._active_writer = None
826 return code
827
828
829class ForwarderWebSocketClient(SSLEnabledWebSocketBaseClient):

Callers 1

_handleMethod · 0.80

Calls 1

WaitReadyMethod · 0.95

Tested by

no test coverage detected