Home > Mobile >  How can I create a windows 10 script which runs a command under specified path?
How can I create a windows 10 script which runs a command under specified path?

Time:12-13

I created a npmruns.bat file with a content:

C:\myfolder>npm run s

I wanted to create a script file which run a command: npm run s under specified location: C:\myfolder , but it doesn't work. I run it by double click (I have an admin rights).

EDIT:
I tried to create a script which can be executed from any location (other than C:\myfolder).

CodePudding user response:

pushd and cd /d will be the options for this:

@echo off
pushd "C:\myfolder"
call npm.cmd run s
popd

This will push to the path of the batch-file as the working directory, popd is not required if you do not need to go back to the starting working directory, which as admin, will be "%systemroot%\system32"

Alternatively you can run:

cd /d "c:\myfolder"
  • Related