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