Giter Site home page Giter Site logo

nils-soderman / vscode-batch-runner Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 4.0 344 KB

Visual Studio Code extension to run batch files in the terminal

Home Page: https://marketplace.visualstudio.com/items?itemName=NilsSoderman.batch-runner

License: MIT License

TypeScript 97.63% Batchfile 2.37%
batch bat vscode runner extension run execute visual-studio-code cmd vscode-extension

vscode-batch-runner's Introduction

Batch Runner

Quickly run batch (.bat / .cmd) files in the VS Code terminal:


Batch runner demo


Executing a batch file

Shortcut

If the active document is a batch file, press F5 to execute it.

Context Menu

This extension adds the options to run a batch file when using right click in the explorer.

Context menu run batch file

Button

When a batch file is open in the editor, a small icon is added to the top right corner which can be used to run the file.

Run batch file button


Running batch file with arguments

VS Code can show a prompt where you can type in the arguments before executing the batch file.

Ways to run the batch file with arguments:

  • Command: "Batch Runner: Run with Arguments" (batch-runner.execBatchFileArgs)
  • In the context menu when right clicking a batch file, select "Run with Arguments"
  • By clicking the dropdown arrow next to the run button and selecting "Run with Arguments"
    Run with arguments button

Running batch file as administrator

Ways to run the batch file with administrator privileges:

  • Command: "Batch Runner: Run as Administrator" (batch-runner.execBatchFileAsAdmin)
  • Holding down Alt when right clicking a file in the explorer will provide you with the option to run the batch file as administrator.
  • By clicking the dropdown arrow next to the run button and selecting "Run as Administrator"

Feedback, Bugs or Requests

If you have any questions, feature requests or run into any bugs, don't hesitate to get in contact with me:

Report an issue
Personal Website

vscode-batch-runner's People

Contributors

dependabot[bot] avatar nils-soderman avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

vscode-batch-runner's Issues

Doesn't work if default terminal is changed

First off, thanks for making this plugin!

I've changed my default terminal to git bash (instead of cmd.exe) and the plugin now tries to run .cmd scripts in bash. It should explicitly open a cmd.exe terminal rather than relying on the default.

Strange behavior each line is run separately

echo Hello
set foo=bar
echo 1
echo 2
echo 3
echo %bar%

What I see in VSCode terminal

C:\Temp>echo Hello
Hello

C:\Temp>set foo=bar

C:\Temp>echo 1
1

C:\Temp>echo 2
2

C:\Temp>echo 3
3

C:\Temp>echo
ECHO is on.

C:\Temp>

Batch Runner v1.0.0
VSCode 1.72.2

Errors running batch files

I'm trying to run a simple bat file in my codespace, but can't get it to work for various reasons. When attempting to run a batch file by right clicking and pressing "run", I get the following output in my terminal:

@Emblin13 โžœ /workspaces/Magic-Queries-Main-Repo (main) $ cls & cd "workspaces/Magic-Queries-Main-Repo" & "workspaces/Magic-Queries-Main-Repo/codespace.bat"
[1] 17583
bash: cls: command not found
[2] 17584
bash: cd: workspaces/Magic-Queries-Main-Repo: No such file or directory
bash: workspaces/Magic-Queries-Main-Repo/codespace.bat: No such file or directory
[1]- Exit 127 cls
[2]+ Exit 1 cd "workspaces/Magic-Queries-Main-Repo"

VSCode also gives me a popup error saying: "Cmd.exe could not be located at C:\windows\System32\cmd.exe". My file does indeed exist in the directory above, so I'm unsure why it's failing to locate the file.

If I try to run the file using F5, I get the same popup error regarding cmd.exe, and the terminal output appears as such:

@Emblin13 โžœ /workspaces/Magic-Queries-Main-Repo (main) $ cls & cd "/workspaces/Magic-Queries-Main-Repo" & "/workspaces/Magic-Queries-Main-Repo codespace.bat"
[1] 19373
bash: cls: command not found
[2] 19374
[1]- Exit 127 cls
bash: /workspaces/Magic-Queries-Main-Repo/codespace.bat: Permission denied

Does not work with names or paths with spaces.

For example:
D:\Desktop\bat's\TEST AREA\file.bat
results in:
"D:/Desktop/bat's/TEST" is not recognized as an internal or external command, program, or executable batch file.
but if you type in the console between quotes
"D:\Desktop\bat's\TEST AREA\file.bat"
it works

Running a Take Command Console .BTM

Hi,
I would like to run a Take Command Console .BTM from VSCode.

I have made the following change;
"batchrunner.cmdPath": "C:\Program Files\JPSoft\TCC_RT_28\tcc.exe"

Unfortunately, I have to rename my test.btm to test.bat in order for it to execute when I press F5.

When I press F5 to run test.bat (which is test.btm, renamed), the batch file is executed in the terminal below, and runs as it should, using tcc.exe instead of cmd.exe

image

If I press F5 with test.btm being the active document, I receive;

image

What do I have to change in VSCode so that I can run a Take Command Console .BTM from VSCode using your extension?

(Note that I am not an experienced VSCode user, and that I am still learning).

The runtime version of TCC, which I am using for running a .BTM from VSCode, can be obtained from https://jpsoft.com/downloads/v28/tcc-rt.exe

Thankyou for your assistance.

Joe

With powershell terminal, this fails.

cmd: The term 'cmd' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

cmd is not defined inside powershell
and Visual Studio code uses powershell (Windows 10)

Support running scripts as admin

My workflow involves running batch scripts as admin.

Perhaps you could add this as a global toggle "Run all scripts as admin"
or... Add an additional right click option "Run this script as admin"

Run batches in the new Terminal

I use this extension to test batch files.
When I run various batch files, they run in the same terminal, so I have trouble with the previous environment variables being remained.

So, we would like to have an option to run the batch file in a new terminal. For example, "Run Batch File in new Terminal" menu or configuring default behavior in the Settings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.