MCPcopy Create free account
hub / github.com/ipython/ipython / getoutput

Method getoutput

IPython/utils/_process_posix.py:79–98  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

77 self.logfile = sys.stdout if logfile is None else logfile
78
79 def getoutput(self, cmd):
80 """Run a command and return its stdout/stderr as a string.
81
82 Parameters
83 ----------
84 cmd : str
85 A command to be executed in the system shell.
86
87 Returns
88 -------
89 output : str
90 A string containing the combination of stdout and stderr from the
91 subprocess, in whatever order the subprocess originally wrote to its
92 file descriptors (so the order of the information in this string is the
93 correct order as would be seen if running the command in a terminal).
94 """
95 try:
96 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
97 except KeyboardInterrupt:
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.

Callers 2

xsysFunction · 0.45
xsysFunction · 0.45

Calls 1

runMethod · 0.45

Tested by 1

xsysFunction · 0.36