Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run .bat in Linux environment

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,

like image 402
Sqeezer Avatar asked Oct 01 '12 21:10

Sqeezer


People also ask

How do I run a .bat file in Linux?

Batch files can be run by typing "start FILENAME. bat". Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal. When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.

How do I run a .bat file in Ubuntu?

It's pretty easy to run a batch file on Windows. Just create a file, change the extension to . bat, and either call the script in PowerShell or double click to execute it.

Is BAT file executable in Linux?

When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands, normally line-by-line. Unix-like operating systems, such as Linux, have a similar, but more flexible, type of file called a shell script. The filename extension . bat is used in DOS and Windows.

Can we run .bat file in Unix?

Yes, there is no . bat file extension on unix.


3 Answers

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.

like image 68
favoretti Avatar answered Oct 12 '22 09:10

favoretti


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

like image 21
Chad Modad Avatar answered Oct 12 '22 07:10

Chad Modad


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.

like image 29
Md Ashraful Islam Avatar answered Oct 12 '22 08:10

Md Ashraful Islam