Home / Microsoft / Microsoft DOS / Set a variable from a file or a command
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Set a variable from a file or a command  (Read 4744 times)
Alex McFar
Guest
« on: April 26, 2004, 03:09:33 AM »

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?


IP logged
PhilC
Guest
« Reply #1 on: May 04, 2004, 08:24:33 PM »

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...

                                Phil_Calhoun@agilent.com
IP logged
stiddy
Guest
« Reply #2 on: May 06, 2004, 08:51:09 AM »

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 %%a
IP logged
stiddy
Guest
« Reply #3 on: May 06, 2004, 09:00:04 AM »

with 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
IP logged
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Set a variable from a file or a command « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.07 seconds with 18 queries.