Get output (possibly including stderr) from a subprocess. Parameters ---------- cmd : str Command to execute (can not end in '&', as background processes are not supported. split : bool, optional If True, split the output into an IPython
(self, cmd, split=True, depth=0)
| 2527 | system = system_piped |
| 2528 | |
| 2529 | def getoutput(self, cmd, split=True, depth=0): |
| 2530 | """Get output (possibly including stderr) from a subprocess. |
| 2531 | |
| 2532 | Parameters |
| 2533 | ---------- |
| 2534 | cmd : str |
| 2535 | Command to execute (can not end in '&', as background processes are |
| 2536 | not supported. |
| 2537 | split : bool, optional |
| 2538 | If True, split the output into an IPython SList. Otherwise, an |
| 2539 | IPython LSString is returned. These are objects similar to normal |
| 2540 | lists and strings, with a few convenience attributes for easier |
| 2541 | manipulation of line-based output. You can use '?' on them for |
| 2542 | details. |
| 2543 | depth : int, optional |
| 2544 | How many frames above the caller are the local variables which should |
| 2545 | be expanded in the command string? The default (0) assumes that the |
| 2546 | expansion variables are in the stack frame calling this function. |
| 2547 | """ |
| 2548 | if cmd.rstrip().endswith('&'): |
| 2549 | # this is *far* from a rigorous test |
| 2550 | raise OSError("Background processes not supported.") |
| 2551 | out = getoutput(self.var_expand(cmd, depth=depth+1)) |
| 2552 | if split: |
| 2553 | out = SList(out.splitlines()) |
| 2554 | else: |
| 2555 | out = LSString(out) |
| 2556 | return out |
| 2557 | |
| 2558 | #------------------------------------------------------------------------- |
| 2559 | # Things related to aliases |