Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduled tasks for running scripts using node won't work

I followed this tutorial for scheduling a task for running a script using node:

https://eddyerburgh.me/run-a-node-script-with-windows-task-scheduler

I left my pc turned on so it could execute the script, but when i came to see if it did execute, there was only a cmd.exe instance open and the task didn't execute the script.

Here's how i configured the action:

Program/Script - C:\WINDOWS\system32\cmd.exe

Arguments - --a -i -c "cd C:\Users\xxxxx\Desktop\folder; node script.js"

Is there another way of doing this?

like image 595
Joao Victor Avatar asked May 31 '18 12:05

Joao Victor


2 Answers

I've managed to make it work by making a .bat file like this:

if not "%minimized%"=="" goto :minimized
set minimized=true
@echo off
cd "<folder where the script is">

start /min cmd /C "node <the script you want to execute>"
goto :EOF
:minimized

Then you can schedule the .bat file to be executed.

like image 113
Joao Victor Avatar answered Nov 07 '22 17:11

Joao Victor


You don't need all those extra arguments. Just use the following settings:

Program/Script: node (or "C:\\Proram Files\node\node.exe" if it's not in your PATH)
Arguments: C:\\Users\user\folder\script.js

It will work.

enter image description here

like image 5
Yura Avatar answered Nov 07 '22 16:11

Yura