0

In Windows 10, I have created a scheduled task using SCHTASKS command to run a node.js file in every 10 minutes using a .bat file. I have used git bash to write that command.

Here is my SCHTASKS command:

schtasks //Create //sc minute //mo 10 //tn "Repeat_10Check" //tr \\runnode.bat

My .bat file is located in root directory i.e. C:\Users\username.

My .bat file's name is runnode.bat

I want to run example.js file which is located in F:\Nodejs\project\subfolder directory, using that .bat file by running the following command:

SCHTASKS //RUN //TN "Repeat_10Check"

Normally in git bash i would write following command to run a node.js file:

cd ../../../F/Nodejs/project/subfolder
node example.js

What should i write in runnode.bat to execute those command using the batch file ?

1 Answer 1

0

Assuming the file will always be in that directory you could provide a static reference to it like so

SCHTASK /Create /SC MINUTE /MO 10 /TN “Check Every 10 Minutes” /TR F:\ Nodejs\project\subfolder\runnode.bat

And in the myJsScriptrun.bat you could just have it do node example.js

So what the above does is run the .bat file located in the same directory as example.js - this allows us to use node example.js - every 10 minutes.

If you can’t / don’t want to change the directory of runnode.bat you could just do within the runnode.bat

node F:\Nodejs\project\subfolder\example.js

Now if you are going to run this as user the above is fine.

Although you can specify parameters such as runasadministrator - Using the /RU tag.

I do suggest giving http://www.robvanderwoude.com/schtasksxp.php a read for further research

Sign up to request clarification or add additional context in comments.

3 Comments

I have followed your suggestion. But when i am executing SCHTASKS //RUN //TN "Repeat_10Check" a pop up command prompt showed up and hide within a blink of an eye. What should i do now ? @Lucy
As I don’t have your available scripts. I did a quick search for you - stackoverflow.com/questions/43650337/… or if you Wonna update your original with both the updated SCHTASKS as well as the updated bat and I can look further into it for you as mine worked perfectly.
I have found it. Change directory command is not same for Windows & Linux. That's why .bat file couldn't find correct folder. Thanks a lot @Lucy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.