Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path does not work in child_process / node

Tags:

node.js

gulp

Below is the current code I use in a Gulp task to run a bat file. The path is absolute.

var gulp = require('gulp');
var exec = require('child_process').exec;

module.exports = function() {

    // Merges the CSS and JS files

    return exec("C:/git/xxxx/Config/BuildScripts/buildassets.bat",
        function (err, stdout, stderr) {
            console.log(stdout);
            console.log(stderr);
        }
    );

};

I want to make it as relative path, but when I change it to a relative path,

return exec('../../../Config/BuildScripts/buildassets.bat'

I get the following error:

'..' is not recognized as an internal or external command, operable program or batch file.

How can I reference this file relatively?

like image 548
Tim Avatar asked Mar 13 '23 07:03

Tim


1 Answers

I am doing this for that purpose but in my main process not in gulp file.

const app = electron.app;
const exec = require('child_process').exec;

var path = app.getAppPath();
exec(`"${path}\\path\\toexe.exe"`, function (err, stdout, stderr) {
   console.log(stdout);
   console.log(stderr);
});
like image 122
Nauman Umer Avatar answered Mar 25 '23 07:03

Nauman Umer