Bat Script Not Found

I’m trying to run a batch script via GitHub Actions on Windows but for some reason it cannot find the batch script.

The batch script is in my Git repository, and I have not cd into any directory but Actions keeps failing by saying " The term ‘test.bat’ is not recognized as the name of a cmdlet, function, script file, or operable | program. Check the spelling of the name, or if a path was included, verify that the path is correct | and try again.

@destinyb-realityi,

What shell are you using to run the batch script in your workflow? The methods to call the .bat file are different based on different shells.
for example, the path of the .bat file is “bat_scripts/test.bat” in the repository.

  1. On CMD
- name: Run bat script on CMD
  shell: cmd
  run: .\bat_scripts\test.bat  # "bat_scripts\test.bat" also can work
  1. On PowerShell
- name: Run bat script on PowerShell
  shell: pwsh
  run: .\bat_scripts\test.bat  # "./bat_scripts/test.bat" also can work
  1. On Bash
- name: Run bat script on Bash
  shell: bash
  run: ./bat_scripts/test.bat

If the problem still exists, please share you repository with us, so that we can check more detailed configurations in your workflow to analyze the root cause.

I’m using the default shell on Windows. It was working fine a few days ago but that was because I had to put the absolute path for the script. For some reason, Actions is saying shell is in a completely different directory than the repo even though it’s not.

@destinyb-realityi,

The default shell on Windows runner is PowerShell.

When you need to call a scripts file on the PowerShell, you can enter the relative path of the scripts file to the current working directory of the PowerShell. Of course, the absolute path also is OK.
Unlike on CMD, on PowerShell the relative path of the called scripts file must have the prefix (’./’ or ‘.\’).

If you omit the prefix (’./’ or ‘.\’) from the entered relative path, you will get the error message:

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

In addition, because you are storing the .bat file in the repository, don’t forget to checkout the repository to the runner machine before you call this .bat file.