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

How does this work?

Discussion in 'T&T - Scripting' started by vefatica, Jun 16, 2014.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    I found an old BTM with this first line:
    Code:
    set z=nothing:rem& cscript "%~f0" //E:VBS //NOLOGO &GOTO:EOF
    The rest is VB script.
    It works. How? In particular, what happens when cscript.exe reads the first line?
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,201
    Likes Received:
    11
    When you are setting a value to a variable that is actually an object then you must follow some special syntax. The SET keyword lets VBScript know that you are setting your variable equal to an object. In addition to this, you also have to set the variable equal to nothing after you are finished with it.

    And I'm guessing that the colon is a statement separator. So VBScript sees a SET z=nothing followed by a REMark.

    TC sees 3 statements - set, cscript, and goto.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    I get the "set" part. Are you sure about the colon and that VBS understands REM?
     
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    697
    Likes Received:
    8
    Code:
    echo %@script[vbscript,a=10:a=a+1:set fso=CreateObject("Scripting.FileSystemObject"):set stdout=fso.GetStandardStream(1):stdout.WriteLine a:Rem This is a comment]
    Joe
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    Got it. Thanks to both of you.
     

Share This Page