1

I am trying to use exec to run a command such as dir with cmd using tcl code, however the terminal window opens up and I am unable to store the result, when the command has run, into a variable ?

This is what I've been trying so far,

set res [exec cmd.exe /c "dir" &];

When I print out the variable using,

puts $res

I get back just three or four digit codes instead of the actual result when the command was run.

Any help is appreciated.

1 Answer 1

2
set res [exec cmd.exe /c "dir" &]

The & at the end of the exec indicates that the command will be processed in the background. The result returned is the process id of the command.

To do what you want, use:

set res [exec cmd.exe /c "dir"]

It would be far more efficient and less resource hungry to use the built-in glob command to get a list of files or search for a file.

 set res [glob *.txt]

 set res [glob -directory {C:/Program Files} *]

References: exec glob

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.