Read the terminal output. :param parent: :param data_ready: :param max_read_bytes: :param sid: :return:
(parent, data_ready, max_read_bytes, sid)
| 201 | |
| 202 | |
| 203 | def read_terminal_data(parent, data_ready, max_read_bytes, sid): |
| 204 | """ |
| 205 | Read the terminal output. |
| 206 | :param parent: |
| 207 | :param data_ready: |
| 208 | :param max_read_bytes: |
| 209 | :param sid: |
| 210 | :return: |
| 211 | """ |
| 212 | if parent in data_ready: |
| 213 | # Read the output from parent fd (terminal). |
| 214 | output = os.read(parent, max_read_bytes) |
| 215 | try: |
| 216 | decode_data = output.decode() |
| 217 | except Exception: |
| 218 | try: |
| 219 | decode_data = output.decode('UTF-8') |
| 220 | except Exception: |
| 221 | decode_data = output.decode('UTF-8', errors='replace') |
| 222 | |
| 223 | sio.emit('pty-output', |
| 224 | {'result': decode_data, |
| 225 | 'error': False}, |
| 226 | namespace='/pty', room=sid) |
| 227 | |
| 228 | |
| 229 | def read_stdout(process, sid, max_read_bytes, win_emit_output=True): |
no test coverage detected