can I run unix shell command in the ModelSim shell?

Discussion in 'VHDL' started by clinton__bill@hotmail.com, Feb 18, 2005.

  1. Guest

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

    Thanks.
    , Feb 18, 2005
    #1
    1. Advertising

  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 http://www.tcl.tk/ to get more info on Tcl.
    --
    Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
    Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
    Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com
    Tim Hubberstey, Feb 18, 2005
    #2
    1. Advertising

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

    >Hi,
    > 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
    command
    - 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
    precedence.

    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.

    HTH
    --
    Jonathan Bromley
    Jonathan Bromley, Feb 18, 2005
    #3
    1. Advertising

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:
    4
    Views:
    1,698
    Terry Hancock
    Apr 23, 2005
  2. Replies:
    2
    Views:
    3,048
  3. ruds
    Replies:
    11
    Views:
    12,557
  4. Sonu
    Replies:
    2
    Views:
    363
    Alex Popescu
    Aug 5, 2007
  5. Pieter Jongsma

    Run UNIX command

    Pieter Jongsma, Sep 9, 2007, in forum: Ruby
    Replies:
    3
    Views:
    104
    Jonas Roberto de Goes Filho (sysdebug)
    Sep 11, 2007
Loading...

Share This Page