3

i'm writing a script in expect and want to save the output of an command in a variable. Is that possible? The command is

echo "text here"| base64

i know i can set a variable with "set" but

set var ["echo text here| base64"]

or

set var [ spawn "echo text here| base64"]

doesn't work. With that i'm just saving the string not the output.

1 Answer 1

5

The exec command returns the output from a command. That lets you set it into a variable:

set var [exec echo "text here" | base64]

However, you can avoid the echo:

set var [exec base64 << "text here"]

And in Tcl 8.6 you can completely skip running an external program:

set var [binary encode base64 "text here"]

There's also a base64 encoder in Tcllib:

package require base64
set var [base64::encode "text here"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.