1.

Solve : Set a variable from a file or a command?

Answer»

I am trying to write a BATCH FILE that will set the value that a command returns to a variable.

For example

I have a command called STRINGS which returns the first 4 letters of a string.

It is used by writing

strings left today,4

and will return toda (the first 4 letters of today)

I want to set a variable to be the value that is returned, so that I can then test it.

I have tried

%6 = (strings left today,4)

if %6 == "toda"

Another way I have tried is to output the value to a file.

strings left today,4 > output.txt

but I don't know how to read the value of output.txt into a variable.

Can someone help me do this?


I noticed you did not have any replies to this. This is bad because I am tring to accomplish the same thing.
Example is: set osver=`ver`
Tring to set the output of the version command into the variable osver. In UNIX scripting this is very simple by just doing "osver=`ver`" and the results of the ver command would be stored in the variable called osver.
  Very interested if you found a solution that works because I have already tried the approach of putting the results into a file and then no sucess in reading it back out into a variable...
   LET me know if you have found a solution and I will check other places and let you know if I find something that works...

                                [email protected]Hope I can help......If you can output strings data into a text file you could then us the following to assign a varible

for /f "tokens=1-2" %%a in (output.txt ) do call c:\another_batch.bat %%awith the code

for /f "tokens=1-2" %%a in (output.txt ) do call c:\another_batch.bat %%a


refer to %1 in another_batch.bat



Discussion

No Comment Found