home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3945 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  2.0 KB

  1. Path: sparky!uunet!decwrl!sdd.hp.com!uakari.primate.wisc.edu!ames!nsisrv!climate.gsfc.nasa.gov!merritt
  2. From: merritt@climate.gsfc.nasa.gov (John H. Merritt)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: NAWK - ?Diff. printf output order when using a pipe.
  5. Message-ID: <1992Jul27.231423.15827@nsisrv.gsfc.nasa.gov>
  6. Date: 27 Jul 92 23:14:23 GMT
  7. References: <1992Jul26.033811.21614@nsisrv.gsfc.nasa.gov> <1992Jul26.221156.12144@nsisrv.gsfc.nasa.gov>
  8. Sender: usenet@nsisrv.gsfc.nasa.gov (Usenet)
  9. Organization: Climate and Radiation Branch
  10. Lines: 34
  11. Nntp-Posting-Host: climate.gsfc.nasa.gov
  12.  
  13. In article <1992Jul26.221156.12144@nsisrv.gsfc.nasa.gov>, merritt@climate.gsfc.nasa.gov (John H. Merritt) writes:
  14. |> In article <1992Jul26.033811.21614@nsisrv.gsfc.nasa.gov>, merritt@climate.gsfc.nasa.gov (John H. Merritt) writes:
  15. |> |> Explain why the following 'nawk' program produces:
  16. |> [ output deleted ]
  17. |> 
  18. |> |> Here is the program:
  19. |> |> ---- cut test.nawk ----
  20. |> |> BEGIN {
  21. |> |>     printf("This is the BEGIN section\n");
  22.         system("fflush()")
  23. |> |> }
  24. [...]
  25.  
  26. |> If there is something like 'fflush' in AWK, that would be great.
  27. |> So far 'close' was the closest thing I found, but the exact syntax eludes
  28. |> me -- if it is the right thing at all.
  29.  
  30. Ha! Completely by accident and totally by surprise, adding
  31. 'system("fflush()")' in the BEGIN section works!  Now, really, I do
  32. know what that statement is trying to do.  As it turns out, anything
  33. in the system call will produce the results I was looking for.  Anything,
  34. that is, that doesn't echo a 'command not found' or other such message.
  35.  
  36. What better function to define than one that self documents. :-)
  37.  
  38. This solution was discovered by a beginner who had
  39. no clue about the difference between commands in
  40. section 1 and functions in section 3.  Kind of a good thing
  41. that 'system' invokes '/bin/sh'.
  42. -- 
  43. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  44. John H. Merritt --> merritt@climate.gsfc.nasa.gov
  45. "I am generally intolerant of ignorance,
  46. but I have made an exception in your case."
  47.