xref: /llvm-project/lldb/test/Shell/Commands/CommandScriptImmediateOutput/Inputs/custom_command.py (revision 193259cbcec77add8e189c4dedeefb15fef50d5e)
1import sys
2
3
4def split(command):
5    command = command.strip()
6    return command.rsplit(' ', 1)
7
8def command_function(debugger, command, exe_ctx, result, internal_dict):
9    result.SetImmediateOutputFile(sys.__stdout__)
10    print('this is a test string, just a test string', file=result)
11
12
13def write_file(debugger, command, exe_ctx, result, internal_dict):
14    args = split(command)
15    path = args[0]
16    mode = args[1]
17    with open(path, mode) as f:
18        result.SetImmediateOutputFile(f)
19        if not mode in ['r']:
20            print('writing to file with mode: ' + mode, file=result)
21