Fossil SCM

Change popen() back to the way it was last week - so that it shows stderr lines on the console rather than consuming them.

drh 2024-02-07 15:46 trunk
Commit 274079a2e19a1489d8d3a8df82df36736236a24ca63a0078b94190b7896e2de0
1 file changed +3 -10
+3 -10
--- src/popen.c
+++ src/popen.c
@@ -129,18 +129,19 @@
129129
FILE **ppOut, /* Write to child using this file descriptor */
130130
int *pChildPid, /* PID of the child process */
131131
int bDirect /* 0: run zCmd as a shell cmd. 1: run directly */
132132
){
133133
#ifdef _WIN32
134
- HANDLE hStdinRd, hStdinWr, hStdoutRd, hStdoutWr;
134
+ HANDLE hStdinRd, hStdinWr, hStdoutRd, hStdoutWr, hStderr;
135135
SECURITY_ATTRIBUTES saAttr;
136136
DWORD childPid = 0;
137137
int fd;
138138
139139
saAttr.nLength = sizeof(saAttr);
140140
saAttr.bInheritHandle = TRUE;
141141
saAttr.lpSecurityDescriptor = NULL;
142
+ hStderr = GetStdHandle(STD_ERROR_HANDLE);
142143
if( !CreatePipe(&hStdoutRd, &hStdoutWr, &saAttr, 4096) ){
143144
win32_fatal_error("cannot create pipe for stdout");
144145
}
145146
SetHandleInformation( hStdoutRd, HANDLE_FLAG_INHERIT, FALSE);
146147
@@ -148,16 +149,11 @@
148149
win32_fatal_error("cannot create pipe for stdin");
149150
}
150151
SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
151152
152153
win32_create_child_process(fossil_utf8_to_unicode(zCmd),
153
- hStdinRd,hStdoutWr,hStdoutWr,&childPid);
154
- /* ^^^^^^^^^ ^^^^^^^^^
155
- ** Send both stdout and stderr to to *ppOut.
156
- ** See check-in 857495ec92a521bb (2024-02-06) and earlier for
157
- ** an example of how to leave stderr going to console */
158
-
154
+ hStdinRd, hStdoutWr, hStderr,&childPid);
159155
*pChildPid = childPid;
160156
*pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
161157
fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
162158
*ppOut = _fdopen(fd, "w");
163159
CloseHandle(hStdinRd);
@@ -198,13 +194,10 @@
198194
close(1);
199195
fd = dup(pin[1]);
200196
if( fd!=1 ) fossil_panic("popen() failed to open file descriptor 1");
201197
close(pin[0]);
202198
close(pin[1]);
203
- close(2);
204
- fd = dup(1);
205
- if( fd!=2 ) fossil_panic("popen() failed to redirect stderr into stdout");
206199
if( bDirect ){
207200
execl(zCmd, zCmd, (char*)0);
208201
}else{
209202
execl("/bin/sh", "/bin/sh", "-c", zCmd, (char*)0);
210203
}
211204
--- src/popen.c
+++ src/popen.c
@@ -129,18 +129,19 @@
129 FILE **ppOut, /* Write to child using this file descriptor */
130 int *pChildPid, /* PID of the child process */
131 int bDirect /* 0: run zCmd as a shell cmd. 1: run directly */
132 ){
133 #ifdef _WIN32
134 HANDLE hStdinRd, hStdinWr, hStdoutRd, hStdoutWr;
135 SECURITY_ATTRIBUTES saAttr;
136 DWORD childPid = 0;
137 int fd;
138
139 saAttr.nLength = sizeof(saAttr);
140 saAttr.bInheritHandle = TRUE;
141 saAttr.lpSecurityDescriptor = NULL;
 
142 if( !CreatePipe(&hStdoutRd, &hStdoutWr, &saAttr, 4096) ){
143 win32_fatal_error("cannot create pipe for stdout");
144 }
145 SetHandleInformation( hStdoutRd, HANDLE_FLAG_INHERIT, FALSE);
146
@@ -148,16 +149,11 @@
148 win32_fatal_error("cannot create pipe for stdin");
149 }
150 SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
151
152 win32_create_child_process(fossil_utf8_to_unicode(zCmd),
153 hStdinRd,hStdoutWr,hStdoutWr,&childPid);
154 /* ^^^^^^^^^ ^^^^^^^^^
155 ** Send both stdout and stderr to to *ppOut.
156 ** See check-in 857495ec92a521bb (2024-02-06) and earlier for
157 ** an example of how to leave stderr going to console */
158
159 *pChildPid = childPid;
160 *pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
161 fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
162 *ppOut = _fdopen(fd, "w");
163 CloseHandle(hStdinRd);
@@ -198,13 +194,10 @@
198 close(1);
199 fd = dup(pin[1]);
200 if( fd!=1 ) fossil_panic("popen() failed to open file descriptor 1");
201 close(pin[0]);
202 close(pin[1]);
203 close(2);
204 fd = dup(1);
205 if( fd!=2 ) fossil_panic("popen() failed to redirect stderr into stdout");
206 if( bDirect ){
207 execl(zCmd, zCmd, (char*)0);
208 }else{
209 execl("/bin/sh", "/bin/sh", "-c", zCmd, (char*)0);
210 }
211
--- src/popen.c
+++ src/popen.c
@@ -129,18 +129,19 @@
129 FILE **ppOut, /* Write to child using this file descriptor */
130 int *pChildPid, /* PID of the child process */
131 int bDirect /* 0: run zCmd as a shell cmd. 1: run directly */
132 ){
133 #ifdef _WIN32
134 HANDLE hStdinRd, hStdinWr, hStdoutRd, hStdoutWr, hStderr;
135 SECURITY_ATTRIBUTES saAttr;
136 DWORD childPid = 0;
137 int fd;
138
139 saAttr.nLength = sizeof(saAttr);
140 saAttr.bInheritHandle = TRUE;
141 saAttr.lpSecurityDescriptor = NULL;
142 hStderr = GetStdHandle(STD_ERROR_HANDLE);
143 if( !CreatePipe(&hStdoutRd, &hStdoutWr, &saAttr, 4096) ){
144 win32_fatal_error("cannot create pipe for stdout");
145 }
146 SetHandleInformation( hStdoutRd, HANDLE_FLAG_INHERIT, FALSE);
147
@@ -148,16 +149,11 @@
149 win32_fatal_error("cannot create pipe for stdin");
150 }
151 SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
152
153 win32_create_child_process(fossil_utf8_to_unicode(zCmd),
154 hStdinRd, hStdoutWr, hStderr,&childPid);
 
 
 
 
 
155 *pChildPid = childPid;
156 *pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
157 fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
158 *ppOut = _fdopen(fd, "w");
159 CloseHandle(hStdinRd);
@@ -198,13 +194,10 @@
194 close(1);
195 fd = dup(pin[1]);
196 if( fd!=1 ) fossil_panic("popen() failed to open file descriptor 1");
197 close(pin[0]);
198 close(pin[1]);
 
 
 
199 if( bDirect ){
200 execl(zCmd, zCmd, (char*)0);
201 }else{
202 execl("/bin/sh", "/bin/sh", "-c", zCmd, (char*)0);
203 }
204

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button