How to set bash to run *.exe with mono?

10,153

Solution 1

Bash has no such feature. Zsh does, you can set up aliases based on extensions:

alias -s exe=mono

This would only work in an interactive shell, however, not when a program invokes another.

Under Linux, you can set up execution of foreign binaries through the binfmt_misc mechanism; see Rolf Bjarne Kvinge. Good Linux distributions set this up automatically as part of the mono runtime package.

If you can't use binfmt_misc because you don't have root permissions, you'll have to settle for wrapper scripts.

#!/bin/sh
exec /path/to/mono "$0.exe" "$@"

Put the wrapper script in the same directory as the .exe file, with the same name without .exe.

Solution 2

It is possible:

  • Become root and turn on the binfmt module in your kernel with this command (you may want to add this command to your /etc/rc.local boot script, so that it will be executed on boot):

    modprobe binfmt

  • Add the line below to your /etc/fstab file:

    binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc none

  • Then, have your system run the following command on boot:

    echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register

  • Be sure to mark your .exe files as executable in the filesystem as well:

    chmod +x myprogram.exe

(from here: http://mono-project.com/Guide)

Note that this is not the recommended way, read the above mentioned Guide page and also the page on how to do application deployment for mono applications.

Solution 3

You might be able to embed the file inside a bash script using the following guide http://www.linuxjournal.com/content/add-binary-payload-your-shell-scripts

Share:
10,153

Related videos on Youtube

desbest
Author by

desbest

Updated on September 18, 2022

Comments

  • desbest
    desbest over 1 year

    Without any DE or even X, I want to use ./my.exe to run mono my.exe, like it works with python scripts.

  • desbest
    desbest over 11 years
    I see, truly I better make loader for each .exe I need