MCPcopy Create free account
hub / github.com/pexpect/pexpect / getProcessResults

Function getProcessResults

tests/pexpectTest.py:26–60  ·  view source on GitHub ↗

executes 'cmd' as a child process and returns the child's output, the duration of execution, and the process exit status. Aborts if child process does not generate output for 'timeLimit' seconds.

(cmd, timeLimit=20)

Source from the content-addressed store, hash-verified

24import sys
25
26def getProcessResults(cmd, timeLimit=20):
27 '''
28 executes 'cmd' as a child process and returns the child's output,
29 the duration of execution, and the process exit status. Aborts if
30 child process does not generate output for 'timeLimit' seconds.
31 '''
32 output = ""
33 startTime = time.time()
34 child = pexpect.spawn(cmd, timeout=10)
35 child.logfile = sys.stdout
36
37 while 1:
38 try:
39 # read_nonblocking will add to 'outout' one byte at a time
40 # newlines can show up as '\r\n' so we kill any '\r's which
41 # will mess up the formatting for the viewer
42 output += child.read_nonblocking(timeout=timeLimit).replace("\r","")
43 except pexpect.EOF as e:
44 print(str(e))
45 # process terminated normally
46 break
47 except pexpect.TIMEOUT as e:
48 print(str(e))
49 output += "\nProcess aborted by FlashTest after %s seconds.\n" % timeLimit
50 print(child.isalive())
51 child.kill(9)
52 break
53
54 endTime = time.time()
55 child.close(force=True)
56
57 duration = endTime - startTime
58 exitStatus = child.exitstatus
59
60 return (output, duration, exitStatus)
61
62cmd = "./ticker.py"
63

Callers 1

pexpectTest.pyFile · 0.85

Calls 5

spawnMethod · 0.45
read_nonblockingMethod · 0.45
isaliveMethod · 0.45
killMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…