Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 41,684 of 42,547    |
|    JJ to Andrew T.    |
|    Re: SET variable to program output    |
|    22 Nov 18 10:17:26    |
   
   From: jj4public@vfemail.net   
      
   On Thu, 22 Nov 2018 00:42:33 -0000 (UTC), Andrew T. wrote:   
   > Thought I would ask here before diving into writing a program...   
   >   
   > I'm looking for a way to assign the output of a program (or contents   
   > of a file would suffice) to an environment variable, similar to bash's   
   > backtick substitution.   
   >   
   > The batch file I'm trying to write will be running on a MS-DOS 6.2   
   > machine.   
   >   
   > Thanks for any suggestions.   
   >   
   > --Andrew   
      
   There's no way to do it directly, and with a batch file alone.   
      
   But first, create a file e.g. "temp.bat" which contains below text without a   
   new line character. i.e. doesn't end with CR+LF.   
      
    @set var=   
      
   The program output must first be filtered using a tool e.g. grep via pipe to   
   get the final text where it will be assigned to the above "var" variable,   
   then redirect the filtered output and append it to the "temp.bat" file. e.g.   
      
    prog | grep {grep-params} >> temp.bat   
      
   So, if the filtered program output is like below:   
      
    TheValue   
      
   The "temp.bat" contents would be:   
      
    @set var=TheValue   
      
   Simply run "temp.bat" using CALL command to set the variable.   
   After that, delete "temp.bat" file.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca