Executing bat file that contains a timeout from Node.js

Viewed 30

I'm trying to execute a bat script that contains a timeout in it. I execute the bat file from node asynchronously but node seem to completely ignore the timeout inside the CMD.

JS FILE:

const fs = require("fs")
const util = require("util")
const exec = util.promisify(require("child_process").exec)

async function executeBat(){
await exec("C:/PktmonScripts/getPhonesMacScript.bat")
do things
}

BAT FILE:

timeout /T 40 /NOBREAK > nul

P.S: The timeout works when I execute the script on cmd..

1 Answers

check your windows command properly if your bat file waits for this, then the program also waits for complete operation you need to call the function at the end

const fs = require("fs")
const util = require("util")
const exec = util.promisify(require("child_process").exec)
     async function executeBat(){
     await exec("C:/PktmonScripts/getPhonesMacScript.bat")
     //I am trying Linux file here but works same as windows
     //await exec("./getPhonesMacScript.sh")
}
executeBat()// -------need to call function at end

in sh file with execute permission

sleep 30

it will sleep for 30 seconds and then the program will be exited

Related