Answer the question
In order to leave comments, you need to log in
What is the correct way to run a .bat file from an Electron application?
Good day. There is an application for Electron 7.1.9. I want to implement auto-update for the application, but since it is portable, the standard electronic method via autoUpdater is not suitable (because the application needs to be installed in the system). I decided to make an update by unpacking the archive after exiting the application. To do this, I wrote a .bat with the following code:
@echo off
@cd /d "%~dp0"
timeout /T 5 /NOBREAK
7z x %cd%\update.zip -o..\"" -r -y
del /s /q .\update.zip
start /d %cd%\..\ app.exe
exit
ipcMain.on('update app', () => {
// Так
const bat = spawn('cmd.exe', ['/c', Path.LAUNCHER_UPDATER]);
// И так
const bat = spawn(Path.LAUNCHER_UPDATER, { cwd: Path.GAME_DIR });
// И вот так
const bat = exec(Path.LAUNCHER_UPDATER, { cwd: Path.GAME_DIR });
bat.stderr.on('data', (data) => {
app.quit();
});
});
shell.openItem(Path.LAUNCHER_UPDATER);
app.quit();
Answer the question
In order to leave comments, you need to log in
Actually, the problem solved itself. The timeout invalid time interval '/t' error appeared when trying to run a batch file in developer mode from a folder other than the project folder. The assembled build of the program runs everything perfectly, when all the files are in their places, then there is no error. Left the option with shell.openItem(Path.LAUNCHER_UPDATER);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question