Claudia F
Claudia F

Reputation: 1

Start Electron/Node.JS app and pass command line args from C#

I have a C# application which launches an Electron app (node.js). I'm attempting to pass a command line argument to the Node.JS application but when I access process.argv from within index.js the argument isn't there. Is there anything specific I should be doing to retrieve this argument from within my node application?

Process process = new Process();
process.StartInfo.FileName = pathToEXE;
process.StartInfo.Arguments = argument;
process.EnableRaisingEvents = true;
process.Start();

Upvotes: 0

Views: 818

Answers (1)

Kailash P
Kailash P

Reputation: 438

Basically process.argv array returns 2 values which are installed location and file opening path. So first of all you should assign those values in global object in main.js as below,

global.sharedObject = { installedLocation: process.argv[0], openFilePath: process.argv[1]}

and access this in your index.js as below,

var remote = require('electron').remote;

var location = remote.getGlobal('sharedObject').installedLocation;

var filePath = remote.getGlobal('sharedObject').openFilePath;

Upvotes: 0

Related Questions