Diff
Not logged in

Differences From Artifact [fe72c1d8f2]:

To Artifact [d10d1f1312]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * tclWinPipe.c --
 *
 *	This file implements the Windows-specific exec pipeline functions, the
 *	"pipe" channel driver, and the "pid" Tcl command.
 *
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclWinPipe.c,v 1.35.2.27 2010/04/25 15:40:55 dgp Exp $
 */

#include "tclWinInt.h"

#include <sys/stat.h>

/*











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * tclWinPipe.c --
 *
 *	This file implements the Windows-specific exec pipeline functions, the
 *	"pipe" channel driver, and the "pid" Tcl command.
 *
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclWinPipe.c,v 1.35.2.28 2010/08/04 21:48:24 dgp Exp $
 */

#include "tclWinInt.h"

#include <sys/stat.h>

/*
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
	if (HasConsole()) {
	    createFlags = 0;
	} else {
	    createFlags = DETACHED_PROCESS;
	}

	if (applType == APPL_DOS) {
	    /*
	     * Under Windows 95, 16-bit DOS applications do not work well with
	     * pipes:
	     *
	     * 1. EOF on a pipe between a detached 16-bit DOS application and
	     * another application is not seen at the other end of the pipe,
	     * so the listening process blocks forever on reads. This inablity
	     * to detect EOF happens when either a 16-bit app or the 32-bit
	     * app is the listener.
	     *
	     * 2. If a 16-bit DOS application (detached or not) blocks when
	     * writing to a pipe, it will never wake up again, and it
	     * eventually brings the whole system down around it.
	     *
	     * The 16-bit application is run as a normal process inside of a
	     * hidden helper console app, and this helper may be run as a
	     * detached process. If any of the stdio handles is a pipe, the
	     * helper application accumulates information into temp files and
	     * forwards it to or from the DOS application as appropriate.
	     * This means that DOS apps must receive EOF from a stdin pipe
	     * before they will actually begin, and must finish generating
	     * stdout or stderr before the data will be sent to the next stage
	     * of the pipe.
	     *
	     * The helper app should be located in the same directory as the
	     * tcl dll.
	     */
	    Tcl_Obj *tclExePtr, *pipeDllPtr;
	    const char *start, *end;
	    int i, fileExists;
	    Tcl_DString pipeDll;

	    if (createFlags != 0) {
		startInfo.wShowWindow = SW_HIDE;
		startInfo.dwFlags |= STARTF_USESHOWWINDOW;
		createFlags = CREATE_NEW_CONSOLE;
	    }

	    Tcl_DStringInit(&pipeDll);
	    Tcl_DStringAppend(&pipeDll, TCL_PIPE_DLL, -1);
	    tclExePtr = TclGetObjNameOfExecutable();
	    Tcl_IncrRefCount(tclExePtr);
	    start = Tcl_GetStringFromObj(tclExePtr, &i);
	    for (end = start + (i-1); end > start; end--) {
		if (*end == '/') {
		    break;
		}
	    }
	    if (*end != '/') {
		Tcl_AppendResult(interp, "no / in executable path name \"",
			start, "\"", (char *) NULL);
		Tcl_DecrRefCount(tclExePtr);
		Tcl_DStringFree(&pipeDll);
		goto end;
	    }
	    i = (end - start) + 1;
	    pipeDllPtr = Tcl_NewStringObj(start, i);
	    Tcl_AppendToObj(pipeDllPtr, Tcl_DStringValue(&pipeDll), -1);
	    Tcl_IncrRefCount(pipeDllPtr);
	    if (Tcl_FSConvertToPathType(interp, pipeDllPtr) != TCL_OK) {
		Tcl_Panic("Tcl_FSConvertToPathType failed");
	    }
	    fileExists = (Tcl_FSAccess(pipeDllPtr, F_OK) == 0);
	    if (!fileExists) {
		Tcl_AppendResult(interp, "Tcl pipe dll \"",
			Tcl_DStringValue(&pipeDll), "\" not found",
			(char *) NULL);
		Tcl_DecrRefCount(tclExePtr);
		Tcl_DecrRefCount(pipeDllPtr);
		Tcl_DStringFree(&pipeDll);
		goto end;
	    }
	    Tcl_DStringAppend(&cmdLine, Tcl_DStringValue(&pipeDll), -1);
	    Tcl_DecrRefCount(tclExePtr);
	    Tcl_DecrRefCount(pipeDllPtr);
	    Tcl_DStringFree(&pipeDll);
	}
    }

    /*
     * cmdLine gets the full command line used to invoke the executable,
     * including the name of the executable itself. The command line arguments
     * in argv[] are stored in cmdLine separated by spaces. Special characters







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
<
<
<
|
<
<
<
<
<







1138
1139
1140
1141
1142
1143
1144
































































1145
1146
1147



1148





1149
1150
1151
1152
1153
1154
1155
	if (HasConsole()) {
	    createFlags = 0;
	} else {
	    createFlags = DETACHED_PROCESS;
	}

	if (applType == APPL_DOS) {
































































	    Tcl_AppendResult(interp,
		    "DOS application process not supported on this platform",
		    (char *) NULL);



	    goto end;





	}
    }

    /*
     * cmdLine gets the full command line used to invoke the executable,
     * including the name of the executable itself. The command line arguments
     * in argv[] are stored in cmdLine separated by spaces. Special characters