trouble redirecting output to environment variable

Jul 31, 2008
9
0
this is peudo-batch (as in pseudo-code but in batch) of what I want! But I don't know the exact 4NT code to do it.
c:\>echo abc| %yyy
(I expect a variable called yyy to contain abc) so
c:\>set
....
yyy=abc


I want to be able to redirect output of a command to an environment variable

I did try going to typing HELP <ENTER>
and I also found from klaus meinhard's page that the INPUT command might do what I want. something about piping to INPUT.
But things I tried didn't work
I noticed something in HELP about the variable only being available to the child process.. that doesn't look promising.
I couldn't see examples in the HELP
The nice thing about DOS 6.22 help was it had examples!
http://www.vfrazee.com/ms-dos/6.22/help/

I know DOS a bit. I did a bit with batch files and remember it(before I knew of 4DOS). So I must be missing something to not see/figure out how to do something as simple as this.
 
jameshanley39 wrote:


> > this is peudo-batch (as in pseudo-code but in batch) of what I
> > want! But I don't know the exact 4NT code to do it.
> > c:\>echo abc| %yyy
> > (I want a variable called yyy to contain abc) so
> > c:\>set
> > ....
> > yyy=abc
> >
> >
> > I did try going to typing HELP <ENTER>
> > and I also found from klaus meinhard's page that the INPUT command
> > might do what I want. something about piping to INPUT.

These syntax examples worked under DOS, where "true" pipes are only
faked by creating a hidden temp-file. Short of recreating that process
(echo abc > tempfile, read value of %yyy from tempfile, delete tempfile)
you can e.g.

set yyy=%@execstr[echo abc]
though from your example it isn't entirely clear why you don't

set yyy=abc

:-)

Mit freundlichem Gruß,

Klaus Meinhard
 
Jun 11, 2008
29
0
Australia
Hi James

jameshanley39 wrote:

> this is peudo-batch (as in pseudo-code but in batch) of what I want! But I don't know the exact 4NT code to do it.
> c:\>echo abc| %yyy
> (I want a variable called yyy to contain abc) so

I am going to assume that this is a simplification and that you are
really trying to set a variable from the output of an external program.
This can be done using "for /f"
eg.
:: get timestamp
for /f %%i in ('xdate.exe +"%%Y%%m%%d-%%H%%M%%S"') do (
set timestamp=%%i
)

HTH
John


> c:\>set
> ....
> yyy=abc
>
>
> I did try going to typing HELP <ENTER>
> and I also found from klaus meinhard's page that the INPUT command might do what I want. something about piping to INPUT.
> But things I tried didn't work
> I noticed something in HELP about the variable only being available to the child process.. that doesn't look promising.
> I couldn't see examples in the HELP
> The nice thing about DOS 6.22 help was it had examples!
> http://www.vfrazee.com/ms-dos/6.22/help/
>
> I know DOS a bit. I did a bit with batch files and remember it(before I knew of 4DOS). So I must be missing something to not know how to do something as simple as this.
>
>
>
>
>


--
Regards
John McMahon
lists@jspect.fastmail.fm

http://catb.org/~esr/faqs/smart-questions.html
 
Jul 31, 2008
9
0
jameshanley39 wrote:
<snip>
set yyy=%@execstr[echo abc]
<snip>
Klaus Meinhard

thanks, that does work nicely..

I am wondering though how I could have found that myself..

I learnt DOS 6.22 by going through HELP.COM, I must have gone through everything item listed there alphabetically, there weren't -that- many, and each thing had examples there.

I can see I would have run into this myself had I gone through the HELP within 4NT, and gone through each thing alphabetically. But any other way I could have found it myself? Any other documentation that mentions this?
I see now infact.. Althoug there are many things there in the HELP index, _EXECSTR with its one line, mentions @EXECSTR, and it does look feasible to look through each of those @ functions. The @ functions being the first bunch of things listed in the rather large index.
 
Jul 31, 2008
9
0
Hi James
I am going to assume that this is a simplification and that you are
really trying to set a variable from the output of an external program.
This can be done using "for /f"
eg.
:: get timestamp
for /f %%i in ('xdate.exe +"%%Y%%m%%d-%%H%%M%%S"') do (
set timestamp=%%i
)

Regards
John McMahon<snip>

I couldn't quite get that working. But from what you said, I managed to get it working!!

I looked at FOR /? and indeed FOR /F can take a command.

It's nice that this works in NT command prompt (even without 4DOS)

C:\>for /f %f in ('echo abc') do set yy=%f
(it worked, yy right at the bottom of set list where I can see it!)
C:\blah> set| find "yy"
yy=abc


C:\blah>for /f %f in ('ver') do echo %f
C:\blah>echo Microsoft
Microsoft
C:\>


It doesn't look like much of a FOR loop though!!!! Not iteration at all.
I guess yours wasn't either. Your %%i wasn't a counter. There's no condition either.. At least with like FOR %f in (*.txt) do echo %f , there is some iteration i.e. through *.txt.
But when taking a command, it seems to be no for loop! Fine by me..FOR /F with a command is a very very useful function!



Many thanks, it works great.


Note-
Though I know what a for loop is and
I am not that familiar with 4DOS and haven't used them that much in batch files either.
I tried copy/pasting what you write into a bat file within 4DOS, but firstly, xdate.exe does not exist.. I couldn't find it via google either, except for some excel thing which I doubt is what you were referring to, it looks like an excel addin.
I don't know where %%y%%m are inputted from.
As far as I know, batch file parameters are like %0-%9, and
from the command prompt, echo %y% gives the same result as echo %dsfsdf% which implies %y% doesn't exist, and it's not listed from SET either. I guess you meant one should set these variables beforehand at the start or or before running the command.
 
jameshanley39 wrote:


> > thanks, that does work nicely..

Okay :-)


> > I am wondering though how I could have found that myself..

While the help for TCC might seem overwhelming at first, a little
experimentation brings forth a page titled "Variable Functions Listed by
Category", which is quite useful when looking for a way to crack a
problem. Of course there's a "Variables by Category" too.

* Klaus Meinhard *
4DOS Info - Info for DOS
www.4dos.info
 
May 20, 2008
3,515
4
Elkridge, MD, USA
K_Meinhard wrote:
| jameshanley39 wrote:
|
|
|
| ---Quote---
||| thanks, that does work nicely..
| ---End Quote---
| Okay :-)
|
|
|
| ---Quote---
||| I am wondering though how I could have found that myself..
| ---End Quote---
| While the help for TCC might seem overwhelming at first, a little
| experimentation brings forth a page titled "Variable Functions Listed
| by Category", which is quite useful when looking for a way to crack a
| problem. Of course there's a "Variables by Category" too.

... and, of course, Commands by Category!
--
Steve
 
Jul 31, 2008
9
0
K_Meinhard wrote:
| jameshanley39 wrote:
|
|
|
| ---Quote---
||| thanks, that does work nicely..
| ---End Quote---
| Okay :-)
|
|
|
| ---Quote---
||| I am wondering though how I could have found that myself..
| ---End Quote---
| While the help for TCC might seem overwhelming at first, a little
| experimentation brings forth a page titled "Variable Functions Listed
| by Category", which is quite useful when looking for a way to crack a
| problem. Of course there's a "Variables by Category" too.

... and, of course, Commands by Category!
--
Steve

I see.. thanks!
 
Similar threads
Thread starter Title Forum Replies Date
R Trouble with @REGSET[] Support 6
J Trouble with @full[] function. Support 3
cgunhouse Trouble with Relational Expression Support 4
old coot TC DIR command has trouble on my SSD Support 2
S Trouble accessing results of forum search Support 2
vefatica Trouble closing TCMD Support 0
M Trouble loading alias list Support 2
Jay Sage CascadePoint Fails to Install (And Some Trouble with TCMD) Support 2
S PDIR has trouble processing filenames with embedded percent sign Support 3
Roedy trouble with COPY /U Support 7
Juanma Barranquero Ctrl-C trouble Support 1
Peter Murschall TPIPE generate unicode on Piping or redirecting Support 3
BobK WAD Redirecting with HEAD & TAIL Support 3
D Syntax error when redirecting eval Support 5
Stefano Piccardi issue: redirecting GOSUB output Support 11
A Redirecting TCC output to a different RDP Session Support 6
A How to? TEE - duplicate output to STDERR Support 3
FreezerBurnt ANSI Prompt messes up list output. Support 39
Ó Recent git output not shown on TCC Support 1
Peter Murschall TEE cannot handle Unicode output Support 2
C TEE command appending null characters to output Support 6
Jesse Heines webform output different in ver. 26 than ver. 25 Support 2
vefatica Piping the output of a DO loop. Support 4
vefatica TCMD output invisible on Win10 Support 22
B How can TCC make an output as a part of command string Support 2
Enigma Take Command 23 duplicates output Support 0
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
S Output from debugger Support 4
M TCC incorrect dir output since Windows 1803 Support 6
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
P Scrollable colored output Support 3
scottb How to? ipconfig output in current window Support 4
David McClelland TEE command puts it's output file in c:\ Support 4
vefatica How to? TPIPE ... see output right away? Support 4
T Fixed Unnecessary debug output Support 3
JohnQSmith Weird DIR output (missing lines) Support 1
J WAD Output redirection in tcexit looses data Support 31
vefatica Console output slower that before Support 8
Mordachai How to capture all console output from a TCMD session? Support 4
C Output continues after Ctrl-Break Support 8
Steve Pitts WAD Strange output from DEL of a non-existent directory Support 7
I perl output is not visible Support 4
I v16 - cls corrupts output stream Support 7
D Fixed Minor problem: output not alligned in the tree command Support 1
vefatica WAD IDE, output window to foreground Support 3
R WAD Strange output from "memory" command Support 1
A How to? Set up a log file for all command output Support 3
A How to? Use TEE with .NET output Support 6
T How to? Logging Output from External Programs Support 4
Frank output of @ipaddress/@ipname Support 1

Similar threads