Run a command and return its stdout/stderr as a string. Parameters ---------- cmd : str A command to be executed in the system shell. Returns ------- output : str A string containing the combination of stdout and stderr from the
(self, cmd)
| 98 | print('^C', file=sys.stderr, end='') |
| 99 | |
| 100 | def getoutput_pexpect(self, cmd): |
| 101 | """Run a command and return its stdout/stderr as a string. |
| 102 | |
| 103 | Parameters |
| 104 | ---------- |
| 105 | cmd : str |
| 106 | A command to be executed in the system shell. |
| 107 | |
| 108 | Returns |
| 109 | ------- |
| 110 | output : str |
| 111 | A string containing the combination of stdout and stderr from the |
| 112 | subprocess, in whatever order the subprocess originally wrote to its |
| 113 | file descriptors (so the order of the information in this string is the |
| 114 | correct order as would be seen if running the command in a terminal). |
| 115 | """ |
| 116 | try: |
| 117 | return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n') |
| 118 | except KeyboardInterrupt: |
| 119 | print('^C', file=sys.stderr, end='') |
| 120 | |
| 121 | def system(self, cmd): |
| 122 | """Execute a command in a subshell. |