Run cmd file linux

Execute Batch file in Windows Subsystem for Linux

Is it possible to execute a .bat file from a Windows Subsystem for Linux (eg. Ubuntu)? It is trivial to run an .exe file from a WSL, but I haven’t found a trivial way to run a .bat . The only way I found is to open cmd.exe , but that is a bit cumbersome to do every time I need to execute a .bat file.

3 Answers 3

Unfortunately at the moment you cannot do so without either using:

…or the following hack using binfmt:

sudo sh -c "echo :WindowsBatch:E::bat::/init: > /proc/sys/fs/binfmt_misc/register" 

The problems with this method are that you’d need to be root, run it each time you opened a bash window, probably do the same for .cmd files too and, I suppose, any bash script name ending with .bat could have issues!

I guess until Microsoft deals with this issue, you’re limited to the above.

Thanks for confirming this. I was afraid this was the case. At least the cmd.exe /c foo.bat command is good enough for me now.

This is what I was looking for. I needed this to launch gradlew.bat in the terminal in Android Studio so I created an alias in my ~/.bashrc : alias gradlewin=’cmd.exe /c gradlew.bat ‘.

If the first answer doesn’t work, try:

sudo sh -c "echo :WindowsBatch:E::bat::/init: > /proc/sys/fs/binfmt_misc/register" 

Then, locate the file. Then make the file executable:

If it says permission denied, just try running it with sudo

Sorry to post on such an old thread but I found a way around it (not sure if it’s something that’s changed from updates, I’m posting on 18/02/2021). I found that running CMD and then feeding it arguments (to link to the requisite batch file) works — it also an accept constructed arguments sent to that command. So in my case (I’m using Debian 10.8 in WSL on 10 Pro):

/mnt/c/windows/system32/cmd.exe /mnt/c/temp/batchfile.bat "-arga -argb -argc" 

I think this may be fairly consistent and workable workaround (just using C:\temp\bathfile.bat as an example, just use the relative /mnt/// path for your needs).

Источник

How do I create a batch file and run it? [duplicate]

Your question is more likely to receive useful answers if it contains some specifics. Such as what type of data is to be processed, including realistic examples of input and output.

Читайте также:  Ammyy admin linux ubuntu

@SergiyKolodyazhnyy The duplicate nominee is closed as too broad. As such the close vote on this one should be «too broad» as well. That said it seems like a reasonable question to me as I was once in the dark myself 🙂

@WinEunuuchs2Unix It is closed but does have an accepted answer, which will give OP what they want, or at least a starting point.

@EliahKagan If a mod agrees perhaps he can reopen that one and then merge the answers from here to there?

@WinEunuuchs2Unix That question, which this received close votes to be duped to, was actually reopened a few hours ago, then closed again as duplicate of that highly voted question. Both of them are listed as «originals» in the duplicate banner here (i.e., this question is duped to both of them). So if answers are to be merged, they’d probably be put there. Do you think that would be useful?

3 Answers 3

To create one use the .sh extension but it doesn’t really matter but it helps future users to quickly determine which file type it is. The bat name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de and it would still run in bash file but I believe it’s a good practice to name them with the .sh file extension.

For the editor, part uses any that is best for you between nano vim gedit emacs , but I believe gedit would be nice to start with.

Источник

How do I create a script file for terminal commands?

In Windows I can write a file containing commands for cmd (usually .cmd or .bat files). When I click on those files it will open cmd.exe and run them commands the file contains. How would I do this in Ubuntu? I’m sure this is a duplicate, but I can’t find my answer.
Its similar to these questions, but they don’t answer the question: Store frequently used terminal commands in a file CMD.exe Emulator in Ubuntu to run .cmd/.bat file

3 Answers 3

First, the most common is to write a file, make sure the first line is

Then save the file. Next mark it executable using chmod +x file

Then when you click (or run the file from the terminal) the commands will be executed. By convention these files usually have no extension, however you can make them end in .sh or any other way.

  • Any (and I mean any) file can be executed in Linux provided the first line is a path to the program that should interpret the file. Common examples include /bin/python , /bin/sh , /bin/dash , but even odd ball things work like /bin/mysql
  • Bash is a full language. It is vastly more complex than cmd.exe in windows. It has a strong programming language that supports functions, loops, conditionals, string operations, etc.
  • These documents may help if you run into problems.
  • If you do not wish to make the file executable then you can run it by passing it as an argument to bash: bash file/to/run.sh
Читайте также:  Linux systemd автозапуск скрипта

A Simple Bash Example

#!/bin/bash echo "This is a shell script" ls -lah echo "I am done running ls" SOMEVAR='text stuff' echo "$SOMEVAR" 

The second method is to record commands using script . Run script then just do stuff. When you are done doing stuff type exit and script will generate a file for you with all the «stuff» you did. This is less used but works quite well for making things like macros. man script for more info.

Источник

Linux Mint Forums

Forum rules
There are no such things as «stupid» questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help. Topics in this forum are automatically closed 6 months after creation.

how to run .cmd file in linux mint 19

Post by faraz_ahmed » Sun Jan 06, 2019 8:40 am

i have a patch file having .cmd format this is working fine in windows 10 so how can i run this patch file?

Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.

Moem Level 22
Posts: 15630 Joined: Tue Nov 17, 2015 9:14 am Location: The Netherlands Contact:

Re: how to run .cmd file in linux mint 19

Post by Moem » Sun Jan 06, 2019 8:42 am

Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!

karlchen Level 22
Posts: 17366 Joined: Sat Dec 31, 2011 7:21 am Location: Germany

Re: how to run .cmd file in linux mint 19

Post by karlchen » Sun Jan 06, 2019 9:40 am

faraz_ahmed wrote: ⤴ Sun Jan 06, 2019 8:40 am i have a patch file having .cmd format this is working fine in windows 10 so how can i run this patch file?

  • It is a Windows batch file, meant to be run via Windows cmd.exe.
  • It cannot be run on Linux (Mint) at all.

Image

The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 500 days now.
The Prophet’s Song

Re: how to run .cmd file in linux mint 19

Post by faraz_ahmed » Sun Jan 06, 2019 10:09 am

Читайте также:  Почему на ноутбуках линукс

karlchen Level 22
Posts: 17366 Joined: Sat Dec 31, 2011 7:21 am Location: Germany

Re: how to run .cmd file in linux mint 19

Post by karlchen » Sun Jan 06, 2019 12:19 pm

Which content is inside the .cmd file? Is it a script file? What’s its name?
Did you perhaps get it from here: Unlocker?
Or where else from?
Without having any details on what kind of script it really is, it will be impossible to answer your question reliably.

Image

The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 500 days now.
The Prophet’s Song

Re: how to run .cmd file in linux mint 19

Post by ralplpcr » Sun Jan 06, 2019 1:08 pm

The simplest answer is «run it in whatever virtual environment your Windows program is running under». But from your answer:

faraz_ahmed wrote: ⤴ Sun Jan 06, 2019 10:09 am VMware player 15 unlocker for mac os high sierra in linux mint

seems to suggest that you’re trying to run a Windows CMD file on an emulated Mac OS? In all likelihood, this probably won’t work. You’d be better off to get a Mac version of the patch, or run Windows in your VMWare & install whatever program you’re attempting to run there, along with your patch.

  • Important Notices
  • ↳ Rules & Notices
  • ↳ Releases & Announcements
  • ↳ Main Edition Support
  • ↳ Beginner Questions
  • ↳ Installation & Boot
  • ↳ Software & Applications
  • ↳ Hardware Support
  • ↳ Graphics Cards & Monitors
  • ↳ Printers & Scanners
  • ↳ Storage
  • ↳ Sound
  • ↳ Networking
  • ↳ Virtual Machines
  • ↳ Desktop & Window Managers
  • ↳ Cinnamon
  • ↳ MATE
  • ↳ Xfce
  • ↳ Other topics
  • ↳ Non-technical Questions
  • ↳ Tutorials
  • Debian Edition Support
  • ↳ LMDE Forums
  • ↳ Beginner Questions
  • ↳ Installation & Boot
  • ↳ Software & Applications
  • ↳ Hardware Support
  • ↳ Networking
  • ↳ Tutorials
  • ↳ Other Topics & Open Discussion
  • ↳ LMDE Archive
  • Interests
  • ↳ Gaming
  • ↳ Scripts & Bash
  • ↳ Programming & Development
  • Customization
  • ↳ Themes, Icons & Wallpaper
  • ↳ Compiz, Conky, Docks & Widgets
  • ↳ Screenshots
  • ↳ Your Artwork
  • Chat
  • ↳ Introduce Yourself
  • ↳ Chat about Linux Mint
  • ↳ Chat about Linux
  • ↳ Open Chat
  • ↳ Suggestions & Feedback
  • International
  • ↳ Translations
  • ↳ Deutsch — German
  • ↳ Español — Spanish
  • ↳ Français — French
  • ↳ Italiano — Italian
  • ↳ Nederlands — Dutch
  • ↳ Português — Portuguese
  • ↳ Русский — Russian
  • ↳ Suomi — Finnish
  • ↳ Other Languages
  • ↳ Čeština-Slovenčina — Czech-Slovak
  • ↳ Magyar — Hungarian
  • ↳ 日本語 — Japanese
  • ↳ Polski — Polish
  • ↳ Svenska — Swedish
  • ↳ Українська — Ukrainian

Powered by phpBB® Forum Software © phpBB Limited

Источник

Оцените статью
Adblock
detector