4
  • Works: vsim, sh -c vsim
  • Doesn't work: echo "vsim" | sh, echo "vsim" | xargs -I {} sh -c "{}"

I want to run ModelSim (vsim) with dmenu, which is triggered using xbindkeys.


Details

vsim is a executable for ModelSim, installed in /opt/altera/modelsim_ase/bin.

When I run it directly, it runs. But when I run it with xargs (eg. from dmenu), it does not work at all - the script itself launches, but probably in the wrong directory or something, I'm really clueless what's wrong.

My path (I added newlines for clarity):

[ondra@x201 ~]$ echo $PATH
/usr/local/sbin:
/usr/local/bin:
/usr/bin:
/usr/lib/jvm/default/bin:
/usr/bin/site_perl:
/usr/bin/vendor_perl:
/usr/bin/core_perl:
/opt/altera/quartus/bin:
/opt/altera/modelsim_ase/bin:
/home/ondra/bin:
/home/ondra/.gem/ruby/2.1.0/bin:
/opt/altera/University_Program/Monitor_Program/bin/bin

Where is vsim?

[ondra@x201 ~]$ which vsim
/opt/altera/modelsim_ase/bin/vsim

Run it with xargs:

[ondra@x201 ~]$ echo "vsim" |  xargs -I {} sh -c '{} &'
[ondra@x201 ~]$ Reading /opt/altera/modelsim_ase/tcl/vsim/pref.tcl 

# 10.1d

# 
# <EOF> 
^C

Run it directly:

[ondra@x201 ~]$ vsim
Reading /opt/altera/modelsim_ase/tcl/vsim/pref.tcl 
# --- and modelsim starts fine now ---

Any ideas welcome.

17
  • You cannot run vsim in this manner. It launches an interactive shell (written in TCL/Tk). What are you trying to do with this? You can find where vsim is located on disk like so: type -f vsim. This feels like an XY Problem, what are you ultimately trying to do with vsim. I worked w/ modemsim/modeltech for 15+ years, you're doing something you shouldn't be.
    – slm
    Nov 18, 2014 at 12:07
  • @slm I have a dmenu-based launcher, and want to be able to run ModelSim with it. What'd you suggest? I'm not too excited with xterm floating around my workspace if I will never look at the outputs there (modelsim shows the errors in it's internal log window).
    – MightyPork
    Nov 18, 2014 at 12:15
  • @slm output of type -f vsim is vsim is /opt/altera/modelsim_ase/bin/vsim. The only thing I want to do is to start modelsim, I think the vsim script does that - and it works when I just go to that folder and do ./vsim. If there's another way, please share.
    – MightyPork
    Nov 18, 2014 at 12:20
  • Can you not run vsim from any directory? The directory that includes vsim is in your $PATH.
    – slm
    Nov 18, 2014 at 12:22
  • @slm Indeed, I can. The problem is, it does not work with the xargs thing. This works: sh -c "vsim", this does not: echo "vsim" | xargs -I {} sh -c "{}". So I concluded there's something rotten in the xargs syntax, but couldn't figure out what.
    – MightyPork
    Nov 18, 2014 at 12:25

1 Answer 1

0

From your experiments, it appears that the vsim program wants its standard input to be connected to a terminal; if it isn't, it either does nothing useful (because it's waiting for input but not getting any) or exits.

$ vsim
$ sh -c vsim

This runs the command normally from a terminal, in the foreground. The command can read input from the terminal.

$ echo "vsim" | sh
$ echo "vsim" | xargs -I {} sh -c "{}"

In both cases, the standard input of vsim is connected to the pipe from the echo command. The vsim command will see a pipe as its input and not a terminal, if it cares. And it will see the end of the file.

$ echo "vsim" |  xargs -I {} sh -c '{} &'

Here, not only is vsim's input connected to the pipe, but the process is executed in the background, so it can't read from the terminal at all (if it tries to, it'll be suspended until it gets foregrounded).

If you want to run vsim inside a pipeline where its standard input would not be connected to the terminal, redirect the input from the terminal to it.

echo "vsim </dev/tty" | sh

If you want to run the program from dmenu, you'll presumably have to open it in a new terminal emulator. Invoke xterm -e vsim instead of vsim.

I'm not familiar with vsim; it's quite possible that there are other ways of running it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .