1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

"Here-document" trickery

Discussion in 'T&T - Scripting' started by samintz, May 25, 2012.

  1. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    The here-document redirection is not limited to external applications. I've used it to do a couple of nifty things that keep my scripts a little cleaner (I think).

    Copy a group of files
    Code:
    (copy /y @con: .) << endtext
    file1
    file2
    file3
    file4
    file5
    endtext
    
    Display a bunch of variables
    Code:
    (do var in @con (echo %var = %[%var])) << endtext
    _4ver
    _batch
    _batchline
    _batchname
    _batchtype
    _cmdline
    _cmdproc
    _cmdspec
    _winuser
    _winver
    _wow64
    _xpixels
    _year
    _ypixels
    endtext
    
     
    epement likes this.
  2. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    wow, really sophisticated !
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    I don't believe it's documented, but TYPE can read from stdin. So you can use here-documents with TYPE:

    Code:
    @echo off
    
    type <<- endtext
       Shell version = %_4ver
       Command line = %_cmdline
       Command shell name = %_cmdproc
       Command shell filename = %_cmdspec
       User name = %_winuser
       Windows version = %_winver
    endtext
    
    
    And you can also put difficult characters like less-than, greater-than, and ampersands in here-documents, which makes them a really simply way to output HTML....
     
  4. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
  5. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    158
    Likes Received:
    0
    You have to select some text in the editor window (to use as the displayed element of the link) before those icons are active
     
  6. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Thank you, Steve. Now I've got it (finally :)).
     
  7. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    170
    Likes Received:
    0
    You do know that EXTPROC works with batch files and rexx scripts too. You store the data file in a rexx script, and the main command file in the batch file. This is 'units.cmd', you type 'units mks' or something, and it produces a neatly presented table of units. Everything in the batch (including extproc), is read by Extproc. Most of it is formatting. It presents a neatly formatted table, partly controlled by the two rexx scripts.

    I had a batch file that produced a fully-formatted word document, complete with letterhead, based pretty much on this sort of thing. For the head and tail, you just have some sort of command like ~head and ~tail to do this.

    Code:
    extproc systemx.rex
    %  , indent 1
    %  ,, indent 2
    %  ; symbol
    %  / full line printed
    %  # k4 formula
    %  unit profile
    %  * change the from formula.
    ~$t (1$X1 = $x)
    /
    * from = '*'
    /Conventional values
    , Specific gravity (spig) ; gcc # si(700,3); kg/m3
    , gravity ; g # si(9,, 9.80665) ; m/s2
    , Joule constant ; j # si(19.9,, 4186.8); K/kg K
    , Atmosphere ; atm # si(720,, 101325); Pa
    , Solar constant; # si(730,,1361); W/m2
    
    
    Code:
    MKS (1E1 = 10)
    
    Conventional values
      Specific gravity (spig)  gcc  1.00000000000000 E  3 kg/m3
      gravity  g  9.80665000000000 E  0 m/s2
      Joule constant  j  3.60000000000000 E  3 K/kg K
      Atmosphere  atm  101.325000000000 E  3 Pa
      Solar constant  1.36100000000000 E  3 W/m2
    
     

Share This Page