1.

Solve : Setting a variable?

Answer»

Hi I am a little NEW to DOS programming and am trying to set a certain commands result to a variable

openssl base64 -d -in out.txt -out temp.txt
set VAR=openssl des3 -d -in temp.txt

echo %VAR%

the echo command returns "openssl des3 -d -in temp.txt " to the command prompt. I need to able to set VAR in order to write my script. ANy suggestions, I am sure the answer is simple I just cannot seem to find it online anywhere.set var=openssl base64 -d -in out.txt -out temp.txt

Start %var%
--------------------
or just %var%Im sorry that doesnt seem to work.
if i do this in the command prompt

openssl des3 -d -in temp.txt

I am PROMPTED for a password and the decrypted string is printed onto the screen. Instead I want that decrypted string to be stored in some sort of VARIABLE like var. With your solution VAR STILL only stores the command itself as a string.

HELP ANYONE!!!!!!!

PS openssl des3 -d -in temp.txt -out out.txt will simply store the result to a file and I do not want that either.
Quote from: shammer on June 11, 2007, 09:09:09 AM

Hi I am a little new to DOS programming and am trying to set a certain commands result to a variable

openssl base64 -d -in out.txt -out temp.txt
set VAR=openssl des3 -d -in temp.txt

echo %VAR%

the echo command returns "openssl des3 -d -in temp.txt " to the command prompt. I need to able to set VAR in order to write my script. ANy suggestions, I am sure the answer is simple I just cannot seem to find it online anywhere.

May I clarify?

You want to run this command

Quote
openssl base64 -d -in out.txt -out temp.txt

This command will place some text into a text file called temp.txt. Do you then wish to place the CONTENTS of temp.txt into a variable? So that (eg) echo %VAR% would show the one line of temp.txt?

Is that correct?

If the answer to the above question is "yes", you could try this

Quote
openssl base64 -d -in out.txt -out temp.txt
for /F "delims==" %%L in (temp.txt) do set VAR=%%L
echo %VAR%

Also, please do not write "HELP ANYONE!!!!!". This is considered to be bad manners. It is like shouting at people. It will not get you an answer faster.



I apologize. Being rude or ill mannered was not my intention in the least.

as to your answer to my post, is there anyway i could do this without writing to a file at all and simply save the result in an environment variable.

Thank youI am not familiar with the openssl command. If an -out file is not specified, does the output APPEAR on the screen?

yes it doesThen this might work

Quote
setlocal enableextensions
setlocal enabledelayedexpansion
for /F "delims= " %%L in ('openssl base64 -d -in out.txt') do set VAR=%%L

If the decrypted text still appears on screen, try this alteration

Quote
for /F "delims= " %%L in ('openssl base64 -d -in out.txt>nul') do set VAR=%%L


Thank you so much Ive been stuck on this one for a while (New to DOS).
Worked like a charmI'm sorry I shouted at you before!

You may not need this line

Quote
setlocal enabledelayedexpansion


Discussion

No Comment Found