|
Answer» Is there a simple way to define the output of a dos command as a variable for use in a batch file? I'll be using both dos622 and the windows nt/xp cmd functions.Yes there is, by filtering the command output thru a FIND command and parsing the results. It would depend on the actual OS and the specific command involved.
Perhaps you could share some details of what you need. 8-)I want to use the output of the time /t command called from a batch to set a variable and then use the variable further on in the batch. The os at present is dos622 but I woud like it to fit win98 thru to xp. Im not sure how find is relevent?I'm not sure the /t switch would be valid for all versions of the command processor. What is valid for XP most likely would not work for DOS 6.22 or even Win98.
This little snippet will work on XP:
Code: [SELECT]@echo off for /f "tokens=1-3 delims=: " %%i in ('time /t') do ( set hh=%%i set mm=%%j set meridian=%%k echo %hh% %mm% %meridian% )
There may be ways to produce the same result on DOS 6.22 that will also work on XP:
Code: [Select]@echo off %comspec% /e:2048/c for %%v in (1 2) do prompt set TM$q$t$_ | find/v "$" >{t}.bat for %%v in (call del) do %%v {t}.bat
for /f "tokens=1-2 delims=:." %%i in ("%tm%") do echo %%i %%j
As you can see, the more current the OS, the easier it gets. 8-)
I don't have my DOS machine available right now, but the LATTER example should work.
THANKS- I'll give it a go. At least Ive got something to play with now.
|