can I run unix shell command in the ModelSim shell?

Discussion in 'VHDL' started by, Feb 18, 2005.

  1. Guest

    Just wonder if I can run unix shell command in the Modelsim shell,
    expecially those time/date command?

    , Feb 18, 2005
    1. Advertisements

  2. wrote:

    > Hi,
    > Just wonder if I can run unix shell command in the Modelsim shell,
    > expecially those time/date command?

    ModelSim uses Tcl as its scripting language so (almost) anything you can
    do from Tcl can be done in ModelSim. Tcl has a variety of shell and file
    interaction commands available. Of course, if you want to execute Unix
    commands, you need to be running on a Unix (or Cygwin) system. Note that
    Tcl commands are NOT directly accessible from VHDL.

    If all you want is time and date, this Tcl command will return it in a
    human-readable format:

    clock format [clock seconds]

    I suggest you go to to get more info on Tcl.
    Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
    Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
    Vancouver, BC, Canada . . . . . . . . . . .
    Tim Hubberstey, Feb 18, 2005
    1. Advertisements

  3. On 18 Feb 2005 10:31:55 -0800, wrote:

    > Just wonder if I can run unix shell command in the Modelsim shell,
    >expecially those time/date command?

    Tim Hubberstey's advice is good - Tcl provides most of what
    you are likely to need, and it's platform-independent.

    However, if you really must execute native operating-system
    commands from within your ModelSim window, find out about
    the Tcl "exec" command. Very much simplified (because
    "exec" has a vast range of options relating to file
    redirection, process control and so on), here's the deal:

    1) If you want to execute a system command from
    the ModelSim Tcl environment:

    VSIM> exec some_command argument1 argument2

    Tcl will ask the operating system to execute "some_command"
    just as if you had typed it, and its arguments, at the
    OS command prompt. The big difference, however, is that
    any output from this command that would have gone to
    the standard output channel (the terminal) is instead
    captured, and the whole of this captured output is then
    returned to Tcl as the result of the exec command. So,
    for example, if you want to find out the contents of
    a file, you could do the following...

    VSIM> set file_contents [exec cat somefile.txt]

    And now the whole of the file is available in the
    Tcl variable called "file_contents".

    (Please don't do this - it's a really stupid way
    to read a file from Tcl!)

    2) But there's a short cut...

    If you simply type any old operating system command
    at the ModelSim Tcl command prompt...

    VSIM> cat junk.vhd

    then it will work!!!!

    It's very far from obvious why this is so, but it's
    extremely convenient. What's happening is this...

    - you type the Unix command
    - Tcl detects that it's not a built-in Tcl or ModelSim
    - First, Tcl checks if it's a unique abbreviation of
    a built-in command (for example, "vsi" would match
    the "vsim" command). If so, it assumes that you
    meant the appropriate command, and does that.
    - If this abbreviation check fails, then Tcl tries
    instead to get the operating system to execute it.
    - Finally, if all this fails, Tcl throws an error.

    Consequently, if you type the "cat" command, Tcl will
    ultimately get the OS to run "cat" for you.

    Note, though, that this is not a very robust mechanism.
    First, it works ONLY at the interactive command line,
    and NOT from within a Tcl script. Second, it can
    easily be subverted by existing Tcl commands. For
    example, if you try to do "ls", Tcl will recognise
    that it is an *ambiguous* abbreviation of several
    different Tcl commands such as lsort, lset, lsearch
    and it will throw an error. And if you type an OS
    command which is also a Tcl command - for example
    "time" - then the Tcl command will of course take

    So, the moral of the story is:
    - learn some Tcl - it's easy, convenient and powerful;
    - learn about the Tcl exec command so that you can
    reliably invoke OS commands on the rare occasions
    that you need them.

    Jonathan Bromley
    Jonathan Bromley, Feb 18, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    Terry Hancock
    Apr 23, 2005
  2. Replies:
  3. ruds
  4. Sonu
    Alex Popescu
    Aug 5, 2007
  5. Pieter Jongsma

    Run UNIX command

    Pieter Jongsma, Sep 9, 2007, in forum: Ruby
    Jonas Roberto de Goes Filho (sysdebug)
    Sep 11, 2007

Share This Page