Error: spawn ./assets/softwares/csharpSoftware.exe ENOENT

25 Views Asked by At

I got a problem with the NSIS Building and ElectronJS Script which I dont understand. I have a Button called "Open CSharp Software" in ElectronJS and If I debug, then the CSharp Software will open without any Errors. But if I Build using NSIS. then it will show:

Error: spawn ./assets/softwares/csharpSoftware.exe ENOENT

which I dont get it, I tried to include the files using "extraFiles" in the package.json or even copy paste the dictionary to root (./) instead of (./assets/softwares/(software)).

Code:

main.js

const { app, ipcMain, BrowserWindow } = require("electron");
const path = require("path");
const { spawn } = require('child_process');
const urlpath = require('url');


function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 1000,
    height: 600,
    minWidth: 680,
    minHeight: 440,
    frame: false,
    icon: path.join(__dirname, 'assets/img/logo.ico'),
    titleBarOverlay: true,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      contextIsolation: false,
      nodeIntegration: true,
      devTools: true,
    },
  });
  mainWindow.loadURL(
    urlpath.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true,
    })
  );

  let csharpAppProcess;

  app.on('ready', () => {
    mainWindow = new BrowserWindow({ width: 800, height: 600 });
    mainWindow.loadFile('index.html');
  });

  // Function to open C# application
  function openCSharpApp() {
    if (csharpAppProcess && !csharpAppProcess.killed) {
      // If running, kill the existing process
      csharpAppProcess.kill();
    }

    // Spawn a new process for the C# application
    csharpAppProcess = spawn('./assets/softwares/csharpSoftware.exe', []);

    csharpAppProcess.on('close', (code) => {
      console.log(`restarted application!`);
    });
  }
  ipcMain.on('openCSharpApp', () => {
    openCSharpApp();
  });
}

package.json:

{
  "name": "application-test",
  "version": "1.0.0",
  "description": "DJsApplication",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "builds": "electron-builder"
  },
  "repository": "",
  "keywords": [
    "djmahirnationtv"
  ],
  "author": "DJMahirNationTV",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^26.0.0",
    "pkg": "^5.8.1",
    "electron-builder": "^24.9.1"
  },
  "dependencies": {
    "electron-is-dev": "^2.0.0",
    "electron-squirrel-startup": "^1.0.0",
    "makensis": "^2.0.8",
    "url": "^0.11.3"
  },
  "build": {
    "productName": "Mineland Moderator Client",
    "appId": "djmahirnationtv.app.id",
    "copyright": "Copyright © 2024 ${author}",
    "win": {
      "target": [
        "nsis"
      ],
      "icon": "./assets/icons/icon.ico"
    },
    "nsis": {
      "deleteAppDataOnUninstall": true,
      "oneClick": true,
      "installerIcon": "./assets/icons/icon.ico",
      "uninstallerIcon": "./assets/icons/icon.ico",
      "uninstallDisplayName": "Software App Uninstaller ${version}",
      "license": "LICENSE.md",
      "createDesktopShortcut": true,
      "runAfterFinish": true,
      "allowToChangeInstallationDirectory": false,
      "include": "build/installer.nsh"
    }
  }
}

the little HTML File:

<a href="#" id="openCSharpAppButton">
  Open CSharp App
</a>

renderer.js:

const { ipcRenderer } = require("electron");
document.getElementById('openCSharpAppButton').addEventListener('click', () => {
    ipcRenderer.send('openCSharpApp');
});

Whats in "softwares" ?:

    DevExpress.Data.v23.2.dll
    Gma.System.MouseKeyHook.dll
    Microsoft.Windows.SDK.NET.dll
    csharpSoftware.deps.json
    csharpSoftware.dll
    csharpSoftware.exe
    csharpSoftware.pdb
    csharpSoftware.runtimeconfig.json
    WinRT.Runtime.dll

Thats it

I tried:

"extraFiles" and I tried to put the csharpSoftware in the same dictionary and I also tried to get help in Discord or everywhere, also Github, there was no solution for it. Same error with Spawn everytime... even ChatGPT didnt wanted to solve it.

0

There are 0 best solutions below