0

I have an existing exe file (processStuff.exe) (it is written in c, in case that is relevant). From a command prompt in Windows I can run:

processStuff.exe -f myDataFile

This will run processStuff.exe which will go on to load the data in the file called myDataFile. That all works fine.

I need to do this programmatically from my Electron app.

So, I add this to my code in my Electron source file:

var spawnFile = require('child_process').execFile;

and I make the call like so:

var executablePath = ''+process.env.SYS_HOME + "\\myFolder\\processStuff.exe";
        
if(fs.existsSync(executablePath))
{
     var opt = function()
     {
         spawnFile(executablePath, ["-f", "myDataFile"], function(err:any, data:any) {  
                                err = err;
                                data = data;
                              console.log(err)
                              console.log(data.toString());                       
                          });  
     }
        
     opt()
}

The exe IS run, but the file is not loaded. So somehow my call to spawnFile is not identical to me running processStuff.exe -f myDataFile from the command console.

Can anyone help me to get this to work? Thanks.

1
  • WAIT: I've gotten it to work by passing the full path to my data file. I think it is an environment variable issue. This works for me however.
    – gnitsuk
    Commented May 22 at 16:19

0

Browse other questions tagged or ask your own question.