can I run unix shell command in the ModelSim shell?

clinton__bill

Usenet Archive
Joined
Feb 18, 2005
Messages
4
Reaction score
0
Hi,
Just wonder if I can run unix shell command in the Modelsim shell, expecially those time/date command?

Thanks.
 

Tim Hubberstey

Usenet Archive
Joined
Jul 24, 2001
Messages
181
Reaction score
0
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.
 

Jonathan Bromley

Usenet Archive
Joined
Jan 5, 2000
Messages
1,302
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top