问题
Is there any way to run .bat file in Linux environment? I have a couple of .bat files, the purpose of them is to call mvn install:install-file scripts. Thus nothing OS dependent is in the scripts.
Thank you,
回答1:
You can use wine or dosbox, but in general there is no known bat
interpreter for linux. There are, however, implementations of various unix shells for windows, there's even a standard toolkit, Windows Services for UNIX
(a.k.a. SUA), which include ksh
implementation and many other nice goodies, so if you want it OS-transparent, you could consider using that and write your scripts in a POSIX-compliant shell scripting language.
--- edit ---
On the other hand, if your script contains nothing else other than an mvn <params>
, you can just make sure the file has execute permissions (x
flag), prepend it with a shell interpreter (like /bin/bash script.bat
) and have a go at it. Success not guaranteed, though.
回答2:
The simple answer is yes there is a way to run it on Linux as long as:
- The commands you are running from the
.bat
file are in the$PATH
on your Linux box - You are not using Microsoft specific BATCH file commands or control structures
You will need to make the file executable and most likely prepend the contents of the file with a line that tells Linux which shell to run the script with. Something like this for bash: #!/bin/bash
回答3:
On Linux Terminal type
wine cmd
After that windows cmd will be played on your terminal. Go to the folder where your .bat file is located and type the bat files name and press enter. It will successfully run.
回答4:
No. The bat
files are windows shell scripts, which probably execute windows commands and expect to run in a windows environment. You need to convert them to shell scripts in order to run them on linux, as your bash shell can not understand dos commands. Luckily, if the install file scripts are truly platform-independent, that should be easy. If you show an example, we may be able to help you translate.
回答5:
Install dosbox
sudo apt install dosbox
Run it with
dosbox
Mount your home folder from your Linux os. Type inside dosbox
MOUNT D /home/<your user>
Switch folder drive
D:
Now if you have a file called my.bat
in your user home directory, then inside doxbox just run it
MY.BAT
回答6:
You could write the equivalent of your .bat script as a shell script.
来源:https://stackoverflow.com/questions/12680998/run-bat-in-linux-environment