Run cmd commands using tcl without opening terminal

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Is it possible to run a cmd command such as 'dir' using exec or another method in tcl and store the output of that command in a string without opening up the actual cmd terminal ?

 

Thank you.

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited February 2017

    Hi,

    did you try:  exec cmd /C dir    

    ?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2017

    Hi,

    did you try:  exec cmd /C dir    

    ?


    @tinh : Yes, i did try it. Although it seems to work for some commands, it does not work for all. For example, if the command is 'dir' it does return the output without opening a terminal and stores it into result when I use,

     set result [exec cmd /c dir]

    However, when I use 

     set result [exec cmd /c ipconfig]

    it does not return the output to my variable and instead opens up a new cmd terminal window and runs the ipconfig command in it, and closes it once the command has run, which is exactly what I want to avoid.

     

    How could I get around this issue ?

  • tinh
    tinh Altair Community Member
    edited February 2017

    Hi,

    ipconfig is an external command (an .exe file) so you should do:

    set result [exec ipconfig.exe]

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2017

    Hi,

    ipconfig is an external command (an .exe file) so you should do:

    set result [exec ipconfig.exe]

    Hi,

    This worked perfectly for me. Thank you.