| 18 | self.process = None |
| 19 | |
| 20 | def start(self): |
| 21 | print("Booting VM...", file=sys.stderr) |
| 22 | self.process = subprocess.Popen( |
| 23 | ['node', self.bridge_path], |
| 24 | stdin=subprocess.PIPE, |
| 25 | stdout=subprocess.PIPE, |
| 26 | stderr=sys.stderr, # Forward stderr (logs) to user console |
| 27 | text=True, |
| 28 | bufsize=1 |
| 29 | ) |
| 30 | |
| 31 | # Wait for READY signal |
| 32 | while True: |
| 33 | line = self.process.stdout.readline() |
| 34 | if not line: |
| 35 | raise RuntimeError("VM process exited unexpectedly") |
| 36 | if line.strip() == "READY": |
| 37 | break |
| 38 | |
| 39 | print("VM Ready.", file=sys.stderr) |
| 40 | |
| 41 | def exec(self, command): |
| 42 | if not self.process: |