How to Run .Exe Executable File from Linux Command Line

How to run .exe executable file from linux command line?

Windows EXE files usually can't run on Linux. You might be successful with wine which emulates MS Windows, though:

wine abc.exe

What do you mean by a runtime variable? A command line argument, or environment variable?

How to run .EXE with inputs on terminal in Unix/Linux?

If the program is just reading from stdin, you can simply do

printf '%s\n%s\n' 'someimage.tif' 'x y z coordinates' | ./Something.exe

Or if the shell you're using is bash:

echo $'someimage.tif\nx y z coordinates' | ./Something.exe

How to run a .exe file with command prompt?

I need to run this file, take input from a text file and save output
in a text file.

Assuming you're on Linux, this should work:

./HelloWorld < input.txt > output.txt

Run executable file from a different user

Your initial starting point both for installing the rpm and for running the service is privileged. For instance, on my CentOS 6 machine, I see in /etc/passwd

games:x:12:100:games:/usr/games:/sbin/nologin

but running as root, I can do this:

$ sudo -u games /bin/sh
sh-4.1$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin
sh-4.1$ id
uid=12(games) gid=100(users) groups=100(users) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
sh-4.1$ cd
sh-4.1$ pwd
/usr/games

In your service script, you can use sudo to run a given process as another user (though a quick check of the same machine does not show this being done).

@msuchy points out that runuser may be preferable. I see that this is relatively recent (according to Ubuntu runuser command?, appeared in util-linux 2.23 -- lacking a date makes release notes less than useful...). The oblique comments in its documentation about PAM make it sound as if this circumvents some of the security checks. Perhaps someone has a better comment about that.

How to run executable file in Ubuntu as a command or service (with Node.js child_process.spawn())?

This is a path issue, node is unable to find service.linux file, use absolute path, issue will be resolved

run an .exe file in UNIX

If this executable came from the Windows environment, it won't run under UNIX/Linux without lots of help.

Two options:

  1. If you have the source code and the application doesn't rely on a lot of Windows specific libraries, you could try compiling it in your current environment.
  2. The WINE emulator can often run Windows executables, depending again on what libraries from Windows are used.

If it isn't a Windows exe and is native to your current environment, then ./exename.exe should work provided you have the permissions to execute it.

How can I run a Windows executable from WSL (Ubuntu) Bash

Native solution

The official solution provided with Windows 10 Insider Preview Update (14951) is based on the almost forgotten binfmt_msc Linux facility for launching binaries. The registration command for the binfmt_misc would be like this (where /init is the provisional binfmt_misc "interpreter" for the win-executables):

sudo echo ":WSLInterop:M::MZ::/init:" > /proc/sys/fs/binfmt_misc/register

And then win-executable would be launched like regular programs:

$ export PATH=$PATH:/mnt/c/Windows/System32
$ notepad.exe
$ ipconfig.exe | grep IPv4 | cut -d: -f2
$ ls -la | findstr.exe foo.txt
$ cmd.exe /c dir

Not that any win-executable must reside in the windows (DrvFs) file-system - not on the Linux's file-system (VolFs) - in order to inherit a proper Windows working-directory.

The cbwin alternative

Untill you get the latest build, project cbwin offers a workaround, by installing 3 new linux commands inside WSL:

  • wcmd: call a win-executable through cmd.exe.
  • wrun: call a win-executable synchronously with CreateProcess, and wait to die (not using cmd.exe).
  • wstart: launch a detached (asynchronously) command (with the use of cmd.exe).

In order to use them, you must:

  1. Install cbwin:

    • a new outbash.exe will be installed in your regular Windows filesystem (somewhere in your %PATH%), plus
    • the 3 linux-commands in the WSL filesystem.
  2. Use this outbash.exe (wherever you installed it) to start WSL, NOT C:\Windows\System32\bash.exe!
  3. Prefix any win-executables with one of those commands, e.g. wrun notepad.

Tip: If the executable launched with wcmd or wrun spawns any children, these survive only for as long that executable remains alive.

In other words, trying to start notepad.exe with wcmd won't work, because notepad will be killed just after having been launched -- Use wrun (synchronously) or wstart (asynchronously) in this case.



Related Topics



Leave a reply



Submit