home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / tcl / 1782 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!think.com!ames!decwrl!decwrl!parc!welch
  3. From: welch@parc.xerox.com (Brent Welch)
  4. Subject: Re: Running Shell commands
  5. Message-ID: <welch.721414106@corvina>
  6. Keywords: Shell, Pipe, TCL/TK, exec, eval
  7. Sender: news@parc.xerox.com
  8. Organization: Xerox PARC
  9. References: <1992Nov06.042401.3241@bnr.ca> <1992Nov6.125342.15092@walter.bellcore.com>
  10. Date: 10 Nov 92 16:48:26 GMT
  11. Lines: 40
  12.  
  13. bytor@grumpy.bellcore.com (Ross Huitt) writes:
  14.  
  15. >In article <1992Nov06.042401.3241@bnr.ca>, tdoan@bnr.ca (Tuan Doan) writes:
  16.  
  17. >|> Hello,
  18. >|>   
  19. >|>    I am trying to get the following shell command to work inside TCL/TK and
  20. >|> is having great difficulty.  If anyone know the solution to this, please 
  21. >|> post.
  22. >|> 
  23. >|>    pr -h '[tdoan@crchh404] /bnr/file1' /bnr/file1 | ipr -D"pageduplex off"
  24.  
  25. >Try something like:
  26. >    exec {pr -h '[tdoan@crchh404] /bnr/file1' /bnr/file1 | ipr "-Dpageduplex off"}
  27.  
  28. >The '{}' will protext you from executing the regular expression and you'll have to
  29. >move the " in the arg to ipr because of the way Tcl handles strings.
  30.  
  31.  
  32. The above suggestion won't work because exec will try to run a program
  33. named "pr -h ...", not pr.  I've just done:
  34.  
  35. exec pr -h {[welch@corvina] /tmp/foo} /tmp/foo | lpr -P snoball
  36.  
  37. The braces will cause pr to get an argv[2] that is "[welch@corvina] /tmp/foo"
  38. There is no need for eval in this simple case.
  39. The following little procedure also works.
  40.  
  41. proc printit { user file } {
  42.     set header "\[$user\]"
  43.     exec pr -h "$header $file" $file | lpr -P snoball
  44. }
  45.  
  46. The trick to remember here is that inside the double quotes there is
  47. only a single level of substitution.  It doesn't matter that the value
  48. of $header looks like a TCL expression.  Only the variable substitution
  49. occurs, and again pr gets an argv[2] of "[welch@corvina] /tmp/foo"
  50. --
  51.  
  52.     Brent Welch
  53.