如何获取使用电子应用程序打开文件的参数 [英] How to get the arguments for opening file with electron app
本文介绍了如何获取使用电子应用程序打开文件的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我很愚蠢,但是我似乎找不到任何有关如何获取电子应用程序启动参数的文档。我的情况是这样的:
Perhaps I'm being stupid but I can't seem to find any documentation on how to get the startup arguments for an electron app. My scenario is something like this:
- 在Windows资源管理器中右键单击文件
- 打开- >我的电子应用程序
- 电子应用程序打开并可以使用文件
我可以电子应用程序打开,但是如何使用右键单击的文件呢?
I can get the electron app to open, but how do I work with the file that was right-clicked?
推荐答案
假设您已经打开方式部分起作用,Windows会将文件名作为命令行参数传递。因此,只需从 process.argv
Assuming that you have the "Open with" portion working, Windows will pass the filename as a command line argument. So just get the file name/path from process.argv
if(process.argv.length >= 2) {
let filePath = process.argv[1];
//open, read, handle file
}
这篇关于如何获取使用电子应用程序打开文件的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文