Tcl Source Code

Hex Artifact Content
Login

Artifact 2822fba342af6335650cb855068cd4c8385338db771b1271178483e04a7a2e88:

Attachment "repro.c" to ticket [91c9bc1c45] added by serhiy.storchaka 2026-11-12 20:28:42.
0000: 2f 2a 20 54 63 6c 20 74 69 63 6b 65 74 20 39 31  /* Tcl ticket 91
0010: 63 39 62 63 31 63 34 35 2e 20 20 57 69 6e 64 6f  c9bc1c45.  Windo
0020: 77 73 20 6f 6e 6c 79 2e 20 20 52 75 6e 20 77 69  ws only.  Run wi
0030: 74 68 20 73 74 64 6f 75 74 20 72 65 64 69 72 65  th stdout redire
0040: 63 74 65 64 20 74 6f 20 61 0a 20 2a 20 66 69 6c  cted to a. * fil
0050: 65 3a 20 20 72 65 70 72 6f 2e 65 78 65 20 3e 20  e:  repro.exe > 
0060: 6f 75 74 2e 74 78 74 20 20 2a 2f 0a 23 69 6e 63  out.txt  */.#inc
0070: 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23  lude <stdio.h>.#
0080: 69 6e 63 6c 75 64 65 20 3c 69 6f 2e 68 3e 0a 23  include <io.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 66 63 6e 74 6c 2e 68  include <fcntl.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 74 63 6c 2e  >.#include <tcl.
00b0: 68 3e 0a 0a 69 6e 74 0a 6d 61 69 6e 28 69 6e 74  h>..int.main(int
00c0: 20 61 72 67 63 2c 20 63 68 61 72 20 2a 2a 61 72   argc, char **ar
00d0: 67 76 29 0a 7b 0a 20 20 20 20 54 63 6c 5f 49 6e  gv).{.    Tcl_In
00e0: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 0a 20  terp *interp;.. 
00f0: 20 20 20 54 63 6c 5f 46 69 6e 64 45 78 65 63 75     Tcl_FindExecu
0100: 74 61 62 6c 65 28 61 72 67 76 5b 30 5d 29 3b 0a  table(argv[0]);.
0110: 20 20 20 20 69 6e 74 65 72 70 20 3d 20 54 63 6c      interp = Tcl
0120: 5f 43 72 65 61 74 65 49 6e 74 65 72 70 28 29 3b  _CreateInterp();
0130: 0a 20 20 20 20 54 63 6c 5f 45 76 61 6c 28 69 6e  .    Tcl_Eval(in
0140: 74 65 72 70 2c 20 22 66 63 6f 6e 66 69 67 75 72  terp, "fconfigur
0150: 65 20 73 74 64 6f 75 74 22 29 3b 09 2f 2a 20 63  e stdout");./* c
0160: 72 65 61 74 65 20 74 68 65 20 73 74 64 6f 75 74  reate the stdout
0170: 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 20 20 20 20   channel */.    
0180: 5f 64 75 70 32 28 5f 6f 70 65 6e 28 22 63 61 70  _dup2(_open("cap
0190: 74 75 72 65 64 2e 74 78 74 22 2c 20 5f 4f 5f 57  tured.txt", _O_W
01a0: 52 4f 4e 4c 59 7c 5f 4f 5f 43 52 45 41 54 7c 5f  RONLY|_O_CREAT|_
01b0: 4f 5f 54 52 55 4e 43 2c 20 30 36 36 36 29 2c 20  O_TRUNC, 0666), 
01c0: 31 29 3b 0a 20 20 20 20 69 66 20 28 54 63 6c 5f  1);.    if (Tcl_
01d0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 63 6c  Eval(interp, "cl
01e0: 6f 73 65 20 5b 6f 70 65 6e 20 72 65 70 72 6f 2e  ose [open repro.
01f0: 63 5d 22 29 20 21 3d 20 54 43 4c 5f 4f 4b 29 20  c]") != TCL_OK) 
0200: 7b 0a 09 66 70 72 69 6e 74 66 28 73 74 64 65 72  {..fprintf(stder
0210: 72 2c 20 22 65 72 72 6f 72 3a 20 5c 22 25 73 5c  r, "error: \"%s\
0220: 22 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72  "\n", Tcl_GetStr
0230: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ingResult(interp
0240: 29 29 3b 0a 09 72 65 74 75 72 6e 20 31 3b 0a 20  ));..return 1;. 
0250: 20 20 20 7d 0a 20 20 20 20 66 70 72 69 6e 74 66     }.    fprintf
0260: 28 73 74 64 65 72 72 2c 20 22 6f 6b 5c 6e 22 29  (stderr, "ok\n")
0270: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a  ;.    return 0;.
0280: 7d 0a                                            }.