##// END OF EJS Templates
fix arguments for commands in _process_posix...
MinRK -
Show More
@@ -89,9 +89,8 b' class ProcessHandler(object):'
89 file descriptors (so the order of the information in this string is the
89 file descriptors (so the order of the information in this string is the
90 correct order as would be seen if running the command in a terminal).
90 correct order as would be seen if running the command in a terminal).
91 """
91 """
92 pcmd = self._make_cmd(cmd)
93 try:
92 try:
94 return pexpect.run(pcmd).replace('\r\n', '\n')
93 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
95 except KeyboardInterrupt:
94 except KeyboardInterrupt:
96 print('^C', file=sys.stderr, end='')
95 print('^C', file=sys.stderr, end='')
97
96
@@ -111,9 +110,8 b' class ProcessHandler(object):'
111 file descriptors (so the order of the information in this string is the
110 file descriptors (so the order of the information in this string is the
112 correct order as would be seen if running the command in a terminal).
111 correct order as would be seen if running the command in a terminal).
113 """
112 """
114 pcmd = self._make_cmd(cmd)
115 try:
113 try:
116 return pexpect.run(pcmd).replace('\r\n', '\n')
114 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
117 except KeyboardInterrupt:
115 except KeyboardInterrupt:
118 print('^C', file=sys.stderr, end='')
116 print('^C', file=sys.stderr, end='')
119
117
@@ -132,12 +130,13 b' class ProcessHandler(object):'
132 # Get likely encoding for the output.
130 # Get likely encoding for the output.
133 enc = text.getdefaultencoding()
131 enc = text.getdefaultencoding()
134
132
135 pcmd = self._make_cmd(cmd)
136 # Patterns to match on the output, for pexpect. We read input and
133 # Patterns to match on the output, for pexpect. We read input and
137 # allow either a short timeout or EOF
134 # allow either a short timeout or EOF
138 patterns = [pexpect.TIMEOUT, pexpect.EOF]
135 patterns = [pexpect.TIMEOUT, pexpect.EOF]
139 # the index of the EOF pattern in the list.
136 # the index of the EOF pattern in the list.
140 EOF_index = 1 # Fix this index if you change the list!!
137 # even though we know it's 1, this call means we don't have to worry if
138 # we change the above list, and forget to change this value:
139 EOF_index = patterns.index(pexpect.EOF)
141 # The size of the output stored so far in the process output buffer.
140 # The size of the output stored so far in the process output buffer.
142 # Since pexpect only appends to this buffer, each time we print we
141 # Since pexpect only appends to this buffer, each time we print we
143 # record how far we've printed, so that next time we only print *new*
142 # record how far we've printed, so that next time we only print *new*
@@ -148,8 +147,7 b' class ProcessHandler(object):'
148 # can set pexpect's search window to be tiny and it won't matter.
147 # can set pexpect's search window to be tiny and it won't matter.
149 # We only search for the 'patterns' timeout or EOF, which aren't in
148 # We only search for the 'patterns' timeout or EOF, which aren't in
150 # the text itself.
149 # the text itself.
151 #child = pexpect.spawn(pcmd, searchwindowsize=1)
150 child = pexpect.spawn(self.sh, args=['-c', cmd])
152 child = pexpect.spawn(pcmd)
153 flush = sys.stdout.flush
151 flush = sys.stdout.flush
154 while True:
152 while True:
155 # res is the index of the pattern that caused the match, so we
153 # res is the index of the pattern that caused the match, so we
@@ -179,11 +177,10 b' class ProcessHandler(object):'
179 finally:
177 finally:
180 # Ensure the subprocess really is terminated
178 # Ensure the subprocess really is terminated
181 child.terminate(force=True)
179 child.terminate(force=True)
180 # add isalive check, to ensure exitstatus is set:
181 child.isalive()
182 return child.exitstatus
182 return child.exitstatus
183
183
184 def _make_cmd(self, cmd):
185 return '%s -c "%s"' % (self.sh, cmd)
186
187
184
188 # Make system() with a functional interface for outside use. Note that we use
185 # Make system() with a functional interface for outside use. Note that we use
189 # getoutput() from the _common utils, which is built on top of popen(). Using
186 # getoutput() from the _common utils, which is built on top of popen(). Using
@@ -86,12 +86,25 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):'
86 self.mktmp('\n'.join(lines))
86 self.mktmp('\n'.join(lines))
87
87
88 def test_system(self):
88 def test_system(self):
89 system('python "%s"' % self.fname)
89 status = system('python "%s"' % self.fname)
90 self.assertEquals(status, 0)
91
92 def test_system_quotes(self):
93 status = system('python -c "import sys"')
94 self.assertEquals(status, 0)
90
95
91 def test_getoutput(self):
96 def test_getoutput(self):
92 out = getoutput('python "%s"' % self.fname)
97 out = getoutput('python "%s"' % self.fname)
93 self.assertEquals(out, 'on stdout')
98 self.assertEquals(out, 'on stdout')
94
99
100 def test_getoutput_quoted(self):
101 out = getoutput('python -c "print 1"')
102 self.assertEquals(out.strip(), '1')
103 out = getoutput("python -c 'print 1'")
104 self.assertEquals(out.strip(), '1')
105 out = getoutput("python -c 'print \"1\"'")
106 self.assertEquals(out.strip(), '1')
107
95 def test_getoutput(self):
108 def test_getoutput(self):
96 out, err = getoutputerror('python "%s"' % self.fname)
109 out, err = getoutputerror('python "%s"' % self.fname)
97 self.assertEquals(out, 'on stdout')
110 self.assertEquals(out, 'on stdout')
General Comments 0
You need to be logged in to leave comments. Login now