_active.remove(self)
return self.sts
-try:
- from os import popen2
-except NameError:
+if hasattr(os, "popen2"):
+ def popen2(cmd, mode='t', bufsize=-1):
+ """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):
"""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
inst = Popen3(cmd, 0, bufsize)
return inst.fromchild, inst.tochild
-try:
- from os import popen3
-except NameError:
+if hasattr(os, "popen3"):
+ def popen3(cmd, mode='t', bufsize=-1):
+ """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):
"""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
inst = Popen3(cmd, 1, bufsize)
return inst.fromchild, inst.tochild, inst.childerr
-try:
- from os import popen4
-except NameError:
- pass # not on unix
+if hasattr(os, "popen4"):
+ def popen4(cmd, mode='t', bufsize=-1):
+ """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_stderr, child_stdin) are returned."""
+ w, r = os.popen4(cmd, mode, bufsize)
+ return r, w
+else:
+ pass # not yet on unix
def _test():
teststr = "abc\n"
static int
_PyPopenCreateProcess(char *cmdstring,
- HANDLE hStdin,
- HANDLE hStdout,
- HANDLE hStderr)
+ HANDLE hStdin,
+ HANDLE hStdout,
+ HANDLE hStderr)
{
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
siStartInfo.wShowWindow = SW_HIDE;
if (CreateProcess(NULL,
- s2,
- NULL,
- NULL,
- TRUE,
- CREATE_NEW_CONSOLE,
- NULL,
- NULL,
- &siStartInfo,
- &piProcInfo) ) {
+ s2,
+ NULL,
+ NULL,
+ TRUE,
+ CREATE_NEW_CONSOLE,
+ NULL,
+ NULL,
+ &siStartInfo,
+ &piProcInfo) ) {
/* Close the handles now so anyone waiting is woken. */
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
* the these handles; resulting in non-closeable handles to the pipes
* being created. */
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
- GetCurrentProcess(), &hChildStdinWrDup, 0,
- FALSE,
- DUPLICATE_SAME_ACCESS);
+ GetCurrentProcess(), &hChildStdinWrDup, 0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS);
if (!fSuccess)
return win32_error("DuplicateHandle", NULL);
return win32_error("CreatePipe", NULL);
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
- GetCurrentProcess(), &hChildStdoutRdDup, 0,
- FALSE,
- DUPLICATE_SAME_ACCESS);
+ GetCurrentProcess(), &hChildStdoutRdDup, 0,
+ FALSE, DUPLICATE_SAME_ACCESS);
if (!fSuccess)
return win32_error("DuplicateHandle", NULL);
if (n != POPEN_4) {
if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
return win32_error("CreatePipe", NULL);
- fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStderrRd,
- GetCurrentProcess(), &hChildStderrRdDup, 0,
- FALSE,
- DUPLICATE_SAME_ACCESS);
+ fSuccess = DuplicateHandle(GetCurrentProcess(),
+ hChildStderrRd,
+ GetCurrentProcess(),
+ &hChildStderrRdDup, 0,
+ FALSE, DUPLICATE_SAME_ACCESS);
if (!fSuccess)
return win32_error("DuplicateHandle", NULL);
/* Close the inheritable version of ChildStdErr that we're using. */
if (n != 4)
CloseHandle(hChildStderrRdDup);
- f = Py_BuildValue("OO",p2,p1);
+ f = Py_BuildValue("OO",p1,p2);
break;
}
PyFile_SetBufSize(p1, 0);
PyFile_SetBufSize(p2, 0);
PyFile_SetBufSize(p3, 0);
- f = Py_BuildValue("OOO",p2,p1,p3);
+ f = Py_BuildValue("OOO",p1,p2,p3);
break;
}
}
if (n == POPEN_4) {
if (!_PyPopenCreateProcess(cmdstring,
- hChildStdinRd,
- hChildStdoutWr,
- hChildStdoutWr))
+ hChildStdinRd,
+ hChildStdoutWr,
+ hChildStdoutWr))
return win32_error("CreateProcess", NULL);
}
else {
if (!_PyPopenCreateProcess(cmdstring,
- hChildStdinRd,
- hChildStdoutWr,
- hChildStderrWr))
+ hChildStdinRd,
+ hChildStdoutWr,
+ hChildStderrWr))
return win32_error("CreateProcess", NULL);
}