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

trouble redirecting output to environment variable

Discussion in 'Support' started by jameshanley39, Aug 1, 2008.

  1. jameshanley39

    Joined:
    Jul 31, 2008
    Messages:
    9
    Likes Received:
    0
    this is peudo-batch (as in pseudo-code but in batch) of what I want! But I don't know the exact 4NT code to do it.
    c:\>echo abc| %yyy
    (I expect a variable called yyy to contain abc) so
    c:\>set
    ....
    yyy=abc


    I want to be able to redirect output of a command to an environment variable

    I did try going to typing HELP <ENTER>
    and I also found from klaus meinhard's page that the INPUT command might do what I want. something about piping to INPUT.
    But things I tried didn't work
    I noticed something in HELP about the variable only being available to the child process.. that doesn't look promising.
    I couldn't see examples in the HELP
    The nice thing about DOS 6.22 help was it had examples!
    http://www.vfrazee.com/ms-dos/6.22/help/

    I know DOS a bit. I did a bit with batch files and remember it(before I knew of 4DOS). So I must be missing something to not see/figure out how to do something as simple as this.
     
  2. K_Meinhard

    Joined:
    May 20, 2008
    Messages:
    311
    Likes Received:
    0
    jameshanley39 wrote:


    These syntax examples worked under DOS, where "true" pipes are only
    faked by creating a hidden temp-file. Short of recreating that process
    (echo abc > tempfile, read value of %yyy from tempfile, delete tempfile)
    you can e.g.

    set yyy=%@execstr[echo abc]
    though from your example it isn't entirely clear why you don't

    set yyy=abc

    :-)

    Mit freundlichem Gruß,

    Klaus Meinhard
     
  3. jmcm

    Joined:
    Jun 11, 2008
    Messages:
    26
    Likes Received:
    0
    Hi James

    jameshanley39 wrote:

    I am going to assume that this is a simplification and that you are
    really trying to set a variable from the output of an external program.
    This can be done using "for /f"
    eg.
    :: get timestamp
    for /f %%i in ('xdate.exe +"%%Y%%m%%d-%%H%%M%%S"') do (
    set timestamp=%%i
    )

    HTH
    John



    --
    Regards
    John McMahon
    lists@jspect.fastmail.fm

    http://catb.org/~esr/faqs/smart-questions.html
     
  4. jameshanley39

    Joined:
    Jul 31, 2008
    Messages:
    9
    Likes Received:
    0
    thanks, that does work nicely..

    I am wondering though how I could have found that myself..

    I learnt DOS 6.22 by going through HELP.COM, I must have gone through everything item listed there alphabetically, there weren't -that- many, and each thing had examples there.

    I can see I would have run into this myself had I gone through the HELP within 4NT, and gone through each thing alphabetically. But any other way I could have found it myself? Any other documentation that mentions this?
    I see now infact.. Althoug there are many things there in the HELP index, _EXECSTR with its one line, mentions @EXECSTR, and it does look feasible to look through each of those @ functions. The @ functions being the first bunch of things listed in the rather large index.
     
  5. jameshanley39

    Joined:
    Jul 31, 2008
    Messages:
    9
    Likes Received:
    0
    I couldn't quite get that working. But from what you said, I managed to get it working!!

    I looked at FOR /? and indeed FOR /F can take a command.

    It's nice that this works in NT command prompt (even without 4DOS)

    C:\>for /f %f in ('echo abc') do set yy=%f
    (it worked, yy right at the bottom of set list where I can see it!)
    C:\blah> set| find "yy"
    yy=abc


    C:\blah>for /f %f in ('ver') do echo %f
    C:\blah>echo Microsoft
    Microsoft
    C:\>


    It doesn't look like much of a FOR loop though!!!! Not iteration at all.
    I guess yours wasn't either. Your %%i wasn't a counter. There's no condition either.. At least with like FOR %f in (*.txt) do echo %f , there is some iteration i.e. through *.txt.
    But when taking a command, it seems to be no for loop! Fine by me..FOR /F with a command is a very very useful function!



    Many thanks, it works great.


    Note-
    Though I know what a for loop is and
    I am not that familiar with 4DOS and haven't used them that much in batch files either.
    I tried copy/pasting what you write into a bat file within 4DOS, but firstly, xdate.exe does not exist.. I couldn't find it via google either, except for some excel thing which I doubt is what you were referring to, it looks like an excel addin.
    I don't know where %%y%%m are inputted from.
    As far as I know, batch file parameters are like %0-%9, and
    from the command prompt, echo %y% gives the same result as echo %dsfsdf% which implies %y% doesn't exist, and it's not listed from SET either. I guess you meant one should set these variables beforehand at the start or or before running the command.
     
  6. K_Meinhard

    Joined:
    May 20, 2008
    Messages:
    311
    Likes Received:
    0
    jameshanley39 wrote:


    Okay :-)


    While the help for TCC might seem overwhelming at first, a little
    experimentation brings forth a page titled "Variable Functions Listed by
    Category", which is quite useful when looking for a way to crack a
    problem. Of course there's a "Variables by Category" too.

    * Klaus Meinhard *
    4DOS Info - Info for DOS
    www.4dos.info
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    K_Meinhard wrote:
    | jameshanley39 wrote:
    |
    |
    |
    | ---Quote---
    ||| thanks, that does work nicely..
    | ---End Quote---
    | Okay :-)
    |
    |
    |
    | ---Quote---
    ||| I am wondering though how I could have found that myself..
    | ---End Quote---
    | While the help for TCC might seem overwhelming at first, a little
    | experimentation brings forth a page titled "Variable Functions Listed
    | by Category", which is quite useful when looking for a way to crack a
    | problem. Of course there's a "Variables by Category" too.

    ... and, of course, Commands by Category!
    --
    Steve
     
  8. jameshanley39

    Joined:
    Jul 31, 2008
    Messages:
    9
    Likes Received:
    0
    I see.. thanks!
     

Share This Page