mirror of https://github.com/python/cpython
- changed the nt.popen2 return values back to
(write, read, ...), based on feedback from GvR. - added tuple-swapping code to popen2.py - fixed some runaway indentation in posixmodule.c
This commit is contained in:
parent
0466132ee4
commit
9ac81f69b2
|
@ -89,9 +89,14 @@ class Popen3:
|
||||||
_active.remove(self)
|
_active.remove(self)
|
||||||
return self.sts
|
return self.sts
|
||||||
|
|
||||||
try:
|
if hasattr(os, "popen2"):
|
||||||
from os import popen2
|
def popen2(cmd, mode='t', bufsize=-1):
|
||||||
except NameError:
|
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
||||||
|
specified, it sets the buffer size for the I/O pipes. The file objects
|
||||||
|
(child_stdout, child_stdin) are returned."""
|
||||||
|
w, r = os.popen2(cmd, mode, bufsize)
|
||||||
|
return r, w
|
||||||
|
else:
|
||||||
def popen2(cmd, mode='t', bufsize=-1):
|
def popen2(cmd, mode='t', bufsize=-1):
|
||||||
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
||||||
specified, it sets the buffer size for the I/O pipes. The file objects
|
specified, it sets the buffer size for the I/O pipes. The file objects
|
||||||
|
@ -104,9 +109,14 @@ except NameError:
|
||||||
inst = Popen3(cmd, 0, bufsize)
|
inst = Popen3(cmd, 0, bufsize)
|
||||||
return inst.fromchild, inst.tochild
|
return inst.fromchild, inst.tochild
|
||||||
|
|
||||||
try:
|
if hasattr(os, "popen3"):
|
||||||
from os import popen3
|
def popen3(cmd, mode='t', bufsize=-1):
|
||||||
except NameError:
|
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
||||||
|
specified, it sets the buffer size for the I/O pipes. The file objects
|
||||||
|
(child_stdout, child_stdin, child_stderr) are returned."""
|
||||||
|
w, r, e = os.popen3(cmd, mode, bufsize)
|
||||||
|
return r, w, e
|
||||||
|
else:
|
||||||
def popen3(cmd, mode='t', bufsize=-1):
|
def popen3(cmd, mode='t', bufsize=-1):
|
||||||
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
||||||
specified, it sets the buffer size for the I/O pipes. The file objects
|
specified, it sets the buffer size for the I/O pipes. The file objects
|
||||||
|
@ -119,10 +129,15 @@ except NameError:
|
||||||
inst = Popen3(cmd, 1, bufsize)
|
inst = Popen3(cmd, 1, bufsize)
|
||||||
return inst.fromchild, inst.tochild, inst.childerr
|
return inst.fromchild, inst.tochild, inst.childerr
|
||||||
|
|
||||||
try:
|
if hasattr(os, "popen4"):
|
||||||
from os import popen4
|
def popen4(cmd, mode='t', bufsize=-1):
|
||||||
except NameError:
|
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
|
||||||
pass # not on unix
|
specified, it sets the buffer size for the I/O pipes. The file objects
|
||||||
|
(child_stdout_stderr, child_stdin) are returned."""
|
||||||
|
w, r = os.popen4(cmd, mode, bufsize)
|
||||||
|
return r, w
|
||||||
|
else:
|
||||||
|
pass # not yet on unix
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
teststr = "abc\n"
|
teststr = "abc\n"
|
||||||
|
|
|
@ -2295,9 +2295,9 @@ win32_popen4(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_PyPopenCreateProcess(char *cmdstring,
|
_PyPopenCreateProcess(char *cmdstring,
|
||||||
HANDLE hStdin,
|
HANDLE hStdin,
|
||||||
HANDLE hStdout,
|
HANDLE hStdout,
|
||||||
HANDLE hStderr)
|
HANDLE hStderr)
|
||||||
{
|
{
|
||||||
PROCESS_INFORMATION piProcInfo;
|
PROCESS_INFORMATION piProcInfo;
|
||||||
STARTUPINFO siStartInfo;
|
STARTUPINFO siStartInfo;
|
||||||
|
@ -2360,15 +2360,15 @@ _PyPopenCreateProcess(char *cmdstring,
|
||||||
siStartInfo.wShowWindow = SW_HIDE;
|
siStartInfo.wShowWindow = SW_HIDE;
|
||||||
|
|
||||||
if (CreateProcess(NULL,
|
if (CreateProcess(NULL,
|
||||||
s2,
|
s2,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
TRUE,
|
TRUE,
|
||||||
CREATE_NEW_CONSOLE,
|
CREATE_NEW_CONSOLE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&siStartInfo,
|
&siStartInfo,
|
||||||
&piProcInfo) ) {
|
&piProcInfo) ) {
|
||||||
/* Close the handles now so anyone waiting is woken. */
|
/* Close the handles now so anyone waiting is woken. */
|
||||||
CloseHandle(piProcInfo.hProcess);
|
CloseHandle(piProcInfo.hProcess);
|
||||||
CloseHandle(piProcInfo.hThread);
|
CloseHandle(piProcInfo.hThread);
|
||||||
|
@ -2404,9 +2404,9 @@ _PyPopen(char *cmdstring, int mode, int n)
|
||||||
* the these handles; resulting in non-closeable handles to the pipes
|
* the these handles; resulting in non-closeable handles to the pipes
|
||||||
* being created. */
|
* being created. */
|
||||||
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
|
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
|
||||||
GetCurrentProcess(), &hChildStdinWrDup, 0,
|
GetCurrentProcess(), &hChildStdinWrDup, 0,
|
||||||
FALSE,
|
FALSE,
|
||||||
DUPLICATE_SAME_ACCESS);
|
DUPLICATE_SAME_ACCESS);
|
||||||
if (!fSuccess)
|
if (!fSuccess)
|
||||||
return win32_error("DuplicateHandle", NULL);
|
return win32_error("DuplicateHandle", NULL);
|
||||||
|
|
||||||
|
@ -2418,9 +2418,8 @@ _PyPopen(char *cmdstring, int mode, int n)
|
||||||
return win32_error("CreatePipe", NULL);
|
return win32_error("CreatePipe", NULL);
|
||||||
|
|
||||||
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
|
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
|
||||||
GetCurrentProcess(), &hChildStdoutRdDup, 0,
|
GetCurrentProcess(), &hChildStdoutRdDup, 0,
|
||||||
FALSE,
|
FALSE, DUPLICATE_SAME_ACCESS);
|
||||||
DUPLICATE_SAME_ACCESS);
|
|
||||||
if (!fSuccess)
|
if (!fSuccess)
|
||||||
return win32_error("DuplicateHandle", NULL);
|
return win32_error("DuplicateHandle", NULL);
|
||||||
|
|
||||||
|
@ -2431,10 +2430,11 @@ _PyPopen(char *cmdstring, int mode, int n)
|
||||||
if (n != POPEN_4) {
|
if (n != POPEN_4) {
|
||||||
if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
|
if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
|
||||||
return win32_error("CreatePipe", NULL);
|
return win32_error("CreatePipe", NULL);
|
||||||
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStderrRd,
|
fSuccess = DuplicateHandle(GetCurrentProcess(),
|
||||||
GetCurrentProcess(), &hChildStderrRdDup, 0,
|
hChildStderrRd,
|
||||||
FALSE,
|
GetCurrentProcess(),
|
||||||
DUPLICATE_SAME_ACCESS);
|
&hChildStderrRdDup, 0,
|
||||||
|
FALSE, DUPLICATE_SAME_ACCESS);
|
||||||
if (!fSuccess)
|
if (!fSuccess)
|
||||||
return win32_error("DuplicateHandle", NULL);
|
return win32_error("DuplicateHandle", NULL);
|
||||||
/* Close the inheritable version of ChildStdErr that we're using. */
|
/* Close the inheritable version of ChildStdErr that we're using. */
|
||||||
|
@ -2516,7 +2516,7 @@ _PyPopen(char *cmdstring, int mode, int n)
|
||||||
if (n != 4)
|
if (n != 4)
|
||||||
CloseHandle(hChildStderrRdDup);
|
CloseHandle(hChildStderrRdDup);
|
||||||
|
|
||||||
f = Py_BuildValue("OO",p2,p1);
|
f = Py_BuildValue("OO",p1,p2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2545,23 +2545,23 @@ _PyPopen(char *cmdstring, int mode, int n)
|
||||||
PyFile_SetBufSize(p1, 0);
|
PyFile_SetBufSize(p1, 0);
|
||||||
PyFile_SetBufSize(p2, 0);
|
PyFile_SetBufSize(p2, 0);
|
||||||
PyFile_SetBufSize(p3, 0);
|
PyFile_SetBufSize(p3, 0);
|
||||||
f = Py_BuildValue("OOO",p2,p1,p3);
|
f = Py_BuildValue("OOO",p1,p2,p3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == POPEN_4) {
|
if (n == POPEN_4) {
|
||||||
if (!_PyPopenCreateProcess(cmdstring,
|
if (!_PyPopenCreateProcess(cmdstring,
|
||||||
hChildStdinRd,
|
hChildStdinRd,
|
||||||
hChildStdoutWr,
|
hChildStdoutWr,
|
||||||
hChildStdoutWr))
|
hChildStdoutWr))
|
||||||
return win32_error("CreateProcess", NULL);
|
return win32_error("CreateProcess", NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!_PyPopenCreateProcess(cmdstring,
|
if (!_PyPopenCreateProcess(cmdstring,
|
||||||
hChildStdinRd,
|
hChildStdinRd,
|
||||||
hChildStdoutWr,
|
hChildStdoutWr,
|
||||||
hChildStderrWr))
|
hChildStderrWr))
|
||||||
return win32_error("CreateProcess", NULL);
|
return win32_error("CreateProcess", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue