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

STDOUT to env var

Discussion in 'TCC/LE Support' started by traub, Apr 28, 2012.

  1. traub

    Joined:
    Apr 28, 2012
    Messages:
    1
    Likes Received:
    0
    As an example under cmd.exe I used the following hack to get an IP address for a computer:

    ping %1 | findstr Pinging | sed "s/^.*\[\(.*\)\].*$/\1/" | set /p IPADDRESS=

    what is the easiest equivalent?

    I'm currently using:

    ping %1 | findstr Pinging | sed "s/^.*\[\(.*\)\].*$/\1/" >%TEMP%\ip
    set /p IPA=<%TEMP%\ip
    del /q %TEMP%\ip

    but would prefer not to use a temporary file.
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    If you used the full TCC, you'd have the variable function @IPADDRESS. Alternately, you can do this:
    ping %1 > clip: %+ set IPADDRESS=%@word[2,%@clip[2]]

    If %1 is jpsoft.com, this will set IPADDRESS to [141.101.125.120]

    NOT TESTED IN TCC/LE!
     
  3. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    You could also use
    Code:
    set IPA=%@execstr[ping -n 1 %1 | sed -n "/^Pinging/s/^.*\[\(.*\)\].*$/\1/p"]
     
  4. Rod Savard

    Joined:
    May 26, 2008
    Messages:
    480
    Likes Received:
    3
    Wouldn't nslookup be a better external command to run than ping?
     

Share This Page