If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
batch programming
Hello to everybody!
How can I put a command result in a variable? For example: set x={output of the command hostname} Does sombody know how to do this on win98? Bye Tobias Goller |
#2
|
|||
|
|||
Is the command, that creates a variable, a batch file, too?
If yes -- you have to run it in the same Command.com process: the parent process (which calls your second batch) does not inherit the variables of the child (second batch) process, if the child process is launching via CALL statement, i.e. in the other Command.com process. So it can be something like: ::---Main batch (main.bat) begin-- if not "%RETCODE%"="" goto CONTIN more initial codes here child.bat :CONTIN set RETCODE= the returned X variable is using here, something like: if "%X%"="2" then echo "Monday" more codes here ::---Main batch (main.bat) end-- ::---Child batch (child.bat) begin-- more codes here, something like: echo.|date|find /i "Mon" if not errorlevel 1 SET X=2 more codes here SET RETCODE=1 MAIN.BAT ::---Child batch (child.bat) end-- Non-empty RETCODE variable says to MAIN.BAT, that it is the return from CHILD.BAT -- but not the initial run of MAIN.BAT. -- Mikhail Zhilin http://www.aha.ru/~mwz Sorry, no technical support by e-mail. Please reply to the newsgroups only. ====== On Mon, 10 Jan 2005 14:18:52 +0100, "Tobias Goller" wrote: Hello to everybody! How can I put a command result in a variable? For example: set x={output of the command hostname} Does sombody know how to do this on win98? Bye Tobias Goller |
#3
|
|||
|
|||
Greetings,
I guess my problem is a bit more tedious. To make things short i need to set an env variable to the output of a batch or command file Ie.: set MYVAR = mybatch.bat Is this possible in Win98? Thank You "Mikhail Zhilin" wrote in message ... Is the command, that creates a variable, a batch file, too? If yes -- you have to run it in the same Command.com process: the parent process (which calls your second batch) does not inherit the variables of the child (second batch) process, if the child process is launching via CALL statement, i.e. in the other Command.com process. So it can be something like: ::---Main batch (main.bat) begin-- if not "%RETCODE%"="" goto CONTIN more initial codes here child.bat :CONTIN set RETCODE= the returned X variable is using here, something like: if "%X%"="2" then echo "Monday" more codes here ::---Main batch (main.bat) end-- ::---Child batch (child.bat) begin-- more codes here, something like: echo.|date|find /i "Mon" if not errorlevel 1 SET X=2 more codes here SET RETCODE=1 MAIN.BAT ::---Child batch (child.bat) end-- Non-empty RETCODE variable says to MAIN.BAT, that it is the return from CHILD.BAT -- but not the initial run of MAIN.BAT. -- Mikhail Zhilin http://www.aha.ru/~mwz Sorry, no technical support by e-mail. Please reply to the newsgroups only. ====== On Mon, 10 Jan 2005 14:18:52 +0100, "Tobias Goller" wrote: Hello to everybody! How can I put a command result in a variable? For example: set x={output of the command hostname} Does sombody know how to do this on win98? Bye Tobias Goller |
#5
|
|||
|
|||
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
World's First Book on Professional Data Recovery Programming | Author Tarun Tyagi | General | 0 | November 26th 04 05:20 PM |
dos programming | barry martin | General | 0 | September 20th 04 02:32 AM |
dos batch files | yousef | General | 0 | August 7th 04 07:52 PM |
dos batch files | yousef | General | 0 | August 7th 04 07:52 PM |
DOS Batch file controlled my PC! | Coolwater0009 | Improving Performance | 1 | May 20th 04 06:09 AM |