启动Electron / Node.JS应用程序并从C#传递命令行参数

时间:2017-04-05 16:41:27

标签: javascript c# node.js command-line-arguments electron

我有一个C#应用程序,它启动一个Electron应用程序(node.js)。我正在尝试将命令行参数传递给Node.JS应用程序但是当我从index.js中访问process.argv时,参数不存在。我是否应该从我的节点应用程序中检索此参数?

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

1 个答案:

答案 0 :(得分:0)

基本上process.argv数组返回2个值,这些值是安装的位置和文件打开路径。首先,您应该在main.js中的全局对象中分配这些值,如下所示,

  

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

并在index.js中访问此内容,如下所示

  

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

     

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

     

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

相关问题