Save output from program to an env variable

Microsoft Windows xp professional w/serv...
April 18, 2010 at 04:01:31
Specs: Windows XP
I want to save the output of a java program to an environment variable, such as:
set RESULTVAR='java javaprogram'

The java javaprogram lists an integer value on the line when running, and I want that output to be stored in RESULTVAR, such as:

> java javaprogram

I want to save this value in an environment variable.

If that is not possible that easily, is it possible to receive yesterday's day in a .bat file, e.g. if today is the 18th that the command returns value 17. Or if today it's March the 1st you will get 28 or 29 depending on the year? (Actually this is what my Java-program is doing...)

Thanks for your help!

See More: Save output from program to an env variable

Report •

April 18, 2010 at 05:55:18
Assuming for the moment that your prog writes to stdout, the script below will set the var. Put your prog in the ().

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('find /v /c "" ^< myfile') do (
set var=%%a

Helping others achieve escape felicity


Report •

April 18, 2010 at 06:08:42
Thanks a lot, I will try that and come back here in case this
does not work as expected... :)

Report •

April 19, 2010 at 02:05:54
set RESULTVAR='java javaprogram'

Correct me if wrong, but this does not work on Windows, only unix/linux. You can redirect the output, but that is not what the above would be doing. Ex.

java javaprogram > C:\java.log 2> C:\java2.err

Then parse the files

Report •

Related Solutions

Ask Question