stark
stark

Reputation: 2256

exec cmd commands using tcl without opening terminal window

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.

Upvotes: 1

Views: 2085

Answers (1)

Brad Lanam
Brad Lanam

Reputation: 5723

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

Upvotes: 2

Related Questions