Compare commits

...
2 changed files with 78 additions and 21 deletions
+71 -20
View File
@@ -502,6 +502,9 @@ TclCreatePipeline(
TclFile pipeIn;
TclFile curInFile, curOutFile, curErrFile;
Tcl_Channel channel;
int newSyntax = 0;
int subArgc;
const char **subArgv = NULL;
if (inPipePtr != NULL) {
*inPipePtr = NULL;
@@ -537,11 +540,20 @@ TclCreatePipeline(
cmdCount = 1;
needCmd = 1;
for (i = 0; i < argc; i++) {
if (newSyntax && needCmd) {
needCmd = 0;
continue;
}
errorToOutput = 0;
skip = 0;
p = argv[i];
switch (*p++) {
case '|':
if ((i == 0) && (*p == '\0')) {
newSyntax = 1;
lastBar = 0;
continue;
}
if (*p == '&') {
p++;
}
@@ -707,11 +719,23 @@ TclCreatePipeline(
break;
default:
/*
* Got a command word, not a redirection.
*/
needCmd = 0;
if (newSyntax) {
Tcl_SetObjResult(interp,
Tcl_ObjPrintf(
"Unsupported redirection \"%s\"",
argv[i]));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "EXEC",
"PIPESYNTAX", NULL);
goto error;
} else {
/*
* Got a command word, not a redirection.
*/
needCmd = 0;
}
break;
}
@@ -859,17 +883,32 @@ TclCreatePipeline(
curInFile = inputFile;
lastArg = argc; /* compiler warning */
for (i = 0; i < argc; i = lastArg + 1) {
int result, joinThisError;
Tcl_Pid pid;
const char *oldName;
/*
* Convert the program name into native form.
*/
if (Tcl_TranslateFileName(interp, argv[i], &execBuffer) == NULL) {
goto error;
if (newSyntax) {
if (i == 0) {
lastArg = i;
continue;
}
if (Tcl_SplitList(interp, argv[i], &subArgc, &subArgv) != TCL_OK) {
goto error;
}
if (Tcl_TranslateFileName(interp, subArgv[0], &execBuffer) == NULL) {
goto error;
}
} else {
/*
* Convert the program name into native form.
*/
if (Tcl_TranslateFileName(interp, argv[i], &execBuffer) == NULL) {
goto error;
}
}
/*
@@ -913,16 +952,24 @@ TclCreatePipeline(
curErrFile = errorFile;
}
/*
* Restore argv[i], since a caller wouldn't expect the contents of
* argv to be modified.
*/
oldName = argv[i];
argv[i] = Tcl_DStringValue(&execBuffer);
result = TclpCreateProcess(interp, lastArg - i, argv + i,
curInFile, curOutFile, curErrFile, &pid);
argv[i] = oldName;
if (newSyntax) {
subArgv[0] = Tcl_DStringValue(&execBuffer);
result = TclpCreateProcess(interp, subArgc, subArgv,
curInFile, curOutFile, curErrFile, &pid);
ckfree(subArgv);
subArgv = NULL;
} else {
/*
* Restore argv[i], since a caller wouldn't expect the contents of
* argv to be modified.
*/
oldName = argv[i];
argv[i] = Tcl_DStringValue(&execBuffer);
result = TclpCreateProcess(interp, lastArg - i, argv + i,
curInFile, curOutFile, curErrFile, &pid);
argv[i] = oldName;
}
if (result != TCL_OK) {
goto error;
}
@@ -1010,6 +1057,10 @@ TclCreatePipeline(
}
ckfree(pidPtr);
}
if (subArgv != NULL) {
ckfree(subArgv);
subArgv = NULL;
}
numPids = -1;
goto cleanup;
}
+7 -1
View File
@@ -372,7 +372,7 @@ test exec-10.1 {errors in exec invocation} -constraints {exec} -body {
exec
} -returnCodes error -result {wrong # args: should be "exec ?-switch ...? arg ?arg ...?"}
test exec-10.2 {errors in exec invocation} -constraints {exec} -body {
exec | cat
exec |& cat
} -returnCodes error -result {illegal use of | or |& in command}
test exec-10.3 {errors in exec invocation} -constraints {exec} -body {
exec cat |
@@ -682,6 +682,12 @@ test exec-19.1 {exec >> uses O_APPEND} -constraints {exec unix} -setup {
} -cleanup {
removeFile $tmpfile
} -result 14
# New Syntax
test exec-20.1 {New exec syntax with sublists} {exec} {
exec | {echo >}
} >
# ----------------------------------------------------------------------
# cleanup