1.

Solve : Equivalent of Unix eval in Windows?

Answer»

Hi,

I want to convert the following unix command line to windows command line:
eval `sb-config --env`

"sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.

So how can I execute the sb-config result in a windows batch script?

The only solution I COULD come up with is:
sb-config --env > sbenv.cmd
call sbenv.cmd
del sbenv.cmd

If anybody has any better suggestions plz let me know.

Thnx n Regards,
PreethYou can use the following:

del set.cmd & FOR /F %V in ('set') do echo SET %V >> set.cmdHi uhoraho,

Thanks for ur reply. I am a newbie to windows scripting. So can u please explain wht this line does?

Regards,
Preethif you...

1. type SET or set at the prompt

2. run the code changing it slightly like this

del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

(It is bad PRACTICE to have a command script with the same name as a built in command)

3. examine the contents of the new file myset.cmd (which is a script)

... you will see for yourself what it does - namely that FOR /F captures the output of the command 'set', line by line, into the loop metavariable %V, and the >> operator echoes these lines, (with the word SET and a space prepended), in append mode, to the named file myset.cmd.

Type FOR /? and SET /? at the prompt for more help.

Hi,

Thanx again...

What I wanted was execute the output of the command line "sb-config --env"

So where should I put this command in the following line:
del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

Regards,
Preeth Quote from: preeth on December 15, 2009, 12:34:03 AM

Thanx again...

What I wanted was execute the output of the command line "sb-config --env"

So where should I put this command in the following line:
del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd


Have you typed FOR /? and read the help?
Yes I read the FOR help.

But I think you didnt get the real requirement.

When I did
del myset.cmd & FOR /F %i in ('sb-config --env') do echo SET %i >> myset.cmd
It was printing 2 lines of "SET set" into the myset.cmd file.

But this one:
del myset.cmd & FOR /F "tokens=1,2" %i in ('sb-config --env') do echo SET %i %j >> myset.cmd
It was printing the command output with a SET prepended to each line.

But I dont want to prefix anything to the output of the command. The command "sb-config --env" output following lines:
set STREAMBASE_HOME="D:\StreamBase\StreamBase.6.3"
set PATH="D:\StreamBase\StreamBase.6.3\bin";%PATH%
I just want to execute them.

I already know that I can do
sb-config --env > sbenv.cmd
call sbenv.cmd
del sbenv.cmd

Is there any better ways of doing this. ie. without creating an temp cmd file.

Thanks and Regards,
Preeth

I dont think it was appreciated that SET appeared in the output

Try this
FOR /F "tokens=1,2" %i in ('sb-config --env') do Call %i %j
I am getting confused myself. What is the result of including

sb-config --env

in a batch script?

or typing it at the prompt?

From the original post

Quote
"sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.
So you want to execute each line. What about this?
Code: [Select]For /f "delims=" %%A in ('sb-config --env') do call %%A
For /f "delims=" %%A in ('sb-config --env') do call %%A is working for me.

Thanks GPL and Salmon.


Discussion

No Comment Found