Skip to content
Tcl Source Code Artifact [6490f699f9]
Login

Artifact [6490f699f9]

Artifact 6490f699f9500adc50c5b83bd35ad78c37f47cd2:

Ticket change [6490f699f9] - New ticket [217776ffffffffff|217776ffff] <i>Patch to fix redirecting stderr in exec on Windows</i>. by nobody on 2000-10-26 00:43:30.
D 2000-10-26T00:43:30
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s582\sBug\nVersion:\s8.0p2\nSubmitDate:\s'1998-05-21'\nLastModified:\s'2000-04-26'\nSeverity:\sMED\nStatus:\sClosed\nSubmitter:\shershey\nChangedBy:\shobbs\nRelatedBugIDs:\s682\nOS:\sAll\sWindows\nFixedDate:\s'2000-10-25'\nFixedInVersion:\sNA\nClosedDate:\s'2000-04-26'\n\n\nConsider\sthe\sfollowing\sTcl\sscript:\n\n\nset\sversion\s[exec\sgcc\s-v\s2>@\sstdout]\n\nif\s{$version\s!=\s""}\sthen\s{\n\n\s\s\s\sputs\s"Got\sversion"\n\n}\selse\s{\n\n\s\s\s\sputs\s"***FAILED***"\n\n}\n\n\nThe\scommand\s`gcc\s-v'\snormally\soutputs\sversion\sinformation\son\sstderr.\n\nThe\s2>@\sstdout\sis\sintended\sto\sredirect\sthe\sstderr\soutput\sto\sstdout,\sso\n\nthat\sit\scan\sbe\seasily\sread\susing\sthe\sexec\scommand.\n\n\nThis\scommands\sworks\sas\sexpected\son\sUnix.\s\sHowever,\swhen\susing\sTcl\n\n8.0p2,\sit\sfails\son\sWindows.\n\n\nWhat\shappens\sis\sthat\swhen\sTclCreatePipeline\ssees\sthe\s2>@\sstdout,\sit\n\ncalls\sFileForRedirect,\swhich\sfinds\sthe\sstdout\schannel\sand\sthen\scalls\n\nTclpMakeFile.\s\sOn\sUnix,\sthis\sreturns\sa\scode\sindicating\sdescriptor\s1.\n\nOn\sWindows,\sthis\sreturns\sa\sfile\shandle\sfor\sstdout.\n\n\nSince\sthe\sexec\scommand\sdoes\snot\sredirect\sstdout,\sTclCreatePipeline\n\nwinds\sup\scalling\sTclCreatePipe\sto\screate\sa\spipe\sfor\sstdout.\n\n\nTclCreatePipeline\sthen\scalls\sTclpCreateProcess.\n\n\nOn\sUnix,\sthis\sforks,\sand\sthe\schild\sfirst\scalls\sSetupStdFile\sfor\n\nstdout,\sand\sthen\scalls\sit\sfor\sstderr.\s\sCalling\sSetupStdFile\sfor\sstdout\n\ndups\sthe\sstdout\spipe\sonto\sfile\sdescriptor\s1.\s\sCalling\sSetupStdFile\sfor\n\nstderr\sfile\sdescriptor\s1,\sas\sreturned\sby\sTclpMakeFile\swhen\scalled\sby\n\nFileForRedirect,\sonto\sfile\sdescriptor\s2.\s\sSo\severything\sworks\sas\n\nexpected:\sboth\sstdout\sand\sstderr\sare\sredirected\sto\sthe\ssame\sfile.\n\n\nOn\sWindows,\showever,\sstdout\sand\sstderr\sare\shandled\sdifferently.\s\sIn\n\nthis\scase,\sstdout\swill\sbe\sredirected\sonto\sthe\sstdout\spipe\sas\sexpected.\n\nHowever,\swhen\sstderr\sis\sredirected,\sit\swill\sbe\sredirected\sfrom\sthe\sold\n\nstdout\shandle,\srather\sthan\sthe\snew\sone.\s\sThe\seffect\sis\sthat\sstdout\n\nwill\sgo\sto\sthe\spipe,\sand\sstderr\swill\sgo\sto\sthe\sconsole.\n\n\nIn\sother\swords,\susing\s2>@\sstderr\shappens\sto\swork\son\sUnix\sbecause\sof\n\nthe\sway\sin\swhich\sthe\sredirection\sdescriptor\sis\srepresented,\sand\sthe\n\norder\sin\swhich\sthe\sdescriptors\sare\sredirected.\s\sOn\sWindows,\swhich\sdoes\n\nnot\salways\suse\sthe\ssame\shandle\snumber\sfor\sstdout,\sit\sfails.\n\n\nI\shave\sappended\sa\spatch\swhich\sfixes\sthis\sproblem\son\sWindows,\sby\n\nchanging\sthe\sway\sin\swhich\sTclCreatePipeline\shandles\sa\sredirection\sof\n\nstderr\son\sstdout.\s\sI\schanged\sTclCreatePipeline\sto\scheck\sfor\sthat\scase\n\nspecially.\s\sWhen\sit\shappens,\swe\sarrange\sto\scall\sTclpCreateProcess\swith\n\nthe\ssame\shandle\sfor\sboth\sstdout\sand\sstderr.\s\sThis\scode\sworks\scorrectly\n\non\sboth\sUnix\sand\sWindows.\s\sOn\sUnix\sit\sis,\sperhaps,\sless\sfragile.\n\n\nWe\sare\susing\sthis\sas\sa\slocal\spatch\sat\sCygnus.\s\sI\swould\slike\ssome\n\nversion\sof\sthis\spatch\sto\sbe\sincluded\sin\sfuture\sTcl\sreleases.\n\nActually,\sto\sbe\smore\sprecise,\sI\swould\slike\sthe\sabove\sTcl\sscript\sto\n\nwork\son\sWindows\sin\sfuture\sreleases,\sand\sthis\spatch\sis\sone\sway\sto\smake\n\nthat\shappen.\s\sPlease\slet\sme\sknow\sif\sI\scan\shelp\sfurther.\n\n\nIan\sTaylor\n\[email protected]\n\n\n***\s/5g/ian/tcl8.0p2/generic/tclPipe.c\s\sWed\sJun\s25\s13:39:57\s1997\n\n---\stclPipe.c\s\s\sFri\sApr\s10\s14:37:15\s1998\n\n***************\sTclCreatePipeline(interp,\sargc,\sargv,\spi\n\n***\s497,502\s****\n\n---\s497,504\s----\n\n\s\s\s\s\s\sint\serrorClose\s=\s0;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sIf\snon-zero,\sthen\serrorFile\sshould\sbe\s\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sclosed\swhen\scleaning\sup.\s*/\n\n\s\s\s\s\s\sint\serrorRelease\s=\s0;\n\n+\s\s\s\s\sint\sjoinError\s=\s0;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sIf\snon-zero,\sstderr\sis\sbeing\sredirected\n\n+\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s*\sonto\sstdout.\s*/\n\n\s\s\s\s\s\schar\s*p;\n\n\s\s\s\s\s\sint\sskip,\slastBar,\slastArg,\si,\sj,\satOK,\sflags,\serrorToOutput;\n\n\s\s\s\s\s\sTcl_DString\sexecBuffer;\n\n***************\sTclCreatePipeline(interp,\sargc,\sargv,\spi\n\n***\s665,674\s****\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\serrorRelease\s=\s0;\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sTclpReleaseFile(errorFile);\n\n\s\s\s\s\s\s\s\s\s\s\s\s}\n\n!\s\s\s\s\s\s\s\s\s\s\serrorFile\s=\sFileForRedirect(interp,\sp,\satOK,\sargv[i],\s\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sargv[i\s+\s1],\sflags,\s&skip,\s&errorClose,\s&errorRelease);\n\n!\s\s\s\s\s\s\s\s\s\s\sif\s(errorFile\s==\sNULL)\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sgoto\serror;\n\n\s\s\s\s\s\s\s\s\s\s\s\s}\n\n\s\s\s\s\s\s\s\s\s\s\s\sbreak;\n\n\s\s\s\s\s\s\s\s}\n\n---\s667,691\s----\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\serrorRelease\s=\s0;\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sTclpReleaseFile(errorFile);\n\n\s\s\s\s\s\s\s\s\s\s\s\s}\n\n!\s\n\n!\s\s\s\s\s\s\s\s\s\s\s/*\sCheck\sspecially\sfor\sthe\scase\sof\sredirecting\sstderr\sonto\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sstdout.\s\s*/\n\n!\s\s\s\s\s\s\s\s\s\s\sjoinError\s=\s0;\n\n!\s\s\s\s\s\s\s\s\s\s\sif\s(*p\s==\s'@'\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s&&\sstrcmp\s((p[1]\s==\s'\\0'\s?\sargv[i\s+\s1]\s:\sp\s+\s1),\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s"stdout")\s==\s0)\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sjoinError\s=\s1;\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sif\s(p[1]\s==\s'\\0')\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sskip\s=\s2;\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s}\selse\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sskip\s=\s1;\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s}\n\n!\s\s\s\s\s\s\s\s\s\s\s}\selse\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\serrorFile\s=\sFileForRedirect(interp,\sp,\satOK,\sargv[i],\s\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sargv[i\s+\s1],\sflags,\s&skip,\s&errorClose,\s&errorRelease);\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sif\s(errorFile\s==\sNULL)\s{\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sgoto\serror;\n\n!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s}\n\n\s\s\s\s\s\s\s\s\s\s\s\s}\n\n\s\s\s\s\s\s\s\s\s\s\s\sbreak;\n\n\s\s\s\s\s\s\s\s}\n\n***************\sTclCreatePipeline(interp,\sargc,\sargv,\spi\n\n***\s755,761\s****\n\n\s\s\s\s\s\s}\n\n\n\s\s\s\s\s\sif\s(errorFile\s==\sNULL)\s{\n\n!\s\s\s\s\s\s\sif\s(errFilePtr\s!=\sNULL)\s{\n\n\s\s\s\s\s\s\s\s\s\s\s\s/*\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s*\sSet\sup\sthe\sstandard\serror\soutput\ssink\sfor\sthe\spipeline,\sif\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s*\srequested.\s\sUse\sa\stemporary\sfile\swhich\sis\sopened,\sthen\sdeleted.\n\n---\s772,780\s----\n\n\s\s\s\s\s\s}\n\n\n\s\s\s\s\s\sif\s(errorFile\s==\sNULL)\s{\n\n!\s\s\s\s\s\s\sif\s(joinError)\s{\n\n!\s\s\s\s\s\s\s\s\s\s\serrorFile\s=\soutputFile;\n\n!\s\s\s\s\s\s\s}\selse\sif\s(errFilePtr\s!=\sNULL)\s{\n\n\s\s\s\s\s\s\s\s\s\s\s\s/*\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s*\sSet\sup\sthe\sstandard\serror\soutput\ssink\sfor\sthe\spipeline,\sif\n\n\s\s\s\s\s\s\s\s\s\s\s\s\s*\srequested.\s\sUse\sa\stemporary\sfile\swhich\sis\sopened,\sthen\sdeleted.\n\n\n\n\n
J foundin obsolete:\s8.0p2
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 60.\sNRE\sand\scoroutines
J title Patch\sto\sfix\sredirecting\sstderr\sin\sexec\son\sWindows
J type Bug
K 217776ffffffffffffffffffffffffffffffffff
U nobody
Z 3dcb2f191158f38e1d1e3647c6fe2452