Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a .bat from inside the IDE

What I want to do is very simple, yet can't find the way to do it.
In my projects I have several .bat files (I know, I'm old) the perform some tasks like running SqlMetal, etc.

I just want to right-click the file and select "run" or something so the bat is executed. How do I do it?

Note: I know I can use Tools -> External Tools, but it's not what I'm looking for

like image 474
Eduardo Molteni Avatar asked Apr 09 '11 15:04

Eduardo Molteni


People also ask

How do you run .bat file?

To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.


1 Answers

If each project has a few batch files associated with it then why not include them in the project and add a new external tool and link it with a custom menu item to run the tool? This will give you a list of batch files in each project and a context menu command to run them. The only downside is that it isn't file type specific (it will let you run any file as a batch file).

Here's how to do it...

Create an external tool called "Run batch file"

  1. Set the Command to: CMD.EXE
  2. Set the Arguments to: /c "$(ItemPath)"
  3. Set the Initial directory to: $(ItemDir)
  4. Check the "use output window" checkbox and then Apply to create the command
  5. Note where the new command appeared in the list of commands. The external commands are numbered from 1 starting below the divider bar. #1 is usually "Create GUID"

Now go to Tools -> Customize and select the commands tab.

  1. Select the Context menu radio button and select "Project and Solution Context menus | Item" from the dropdown.
  2. Now use "Add Command..." to add a new command
  3. In the Categories list select "Tools"
  4. From the commands select the "External Command #" that corresponds to the position of the "Run Batch file" custom command you noted the number of in step 5 above.
  5. Move it to the correct position in the list add keyboard shortcuts etc.
  6. Close the dialog.

Now right click on the batch file and you should see a "Run batch file" menu item. This will execute the batch file and show its output in the VS Output window.

like image 151
Ade Miller Avatar answered Sep 19 '22 16:09

Ade Miller