- 1 year ago
Electron Windows Production Bundle Command Line Arguments
When running an Electron application with a production bundle on Windows, you can pass command-line arguments to the application by appending them to the command used to launch the application.
Assuming you have a bundled Electron application named app.exe
, you can pass command-line arguments as follows:
cssapp.exe --arg1 value1 --arg2 value2
Here's an example of launching the bundled Electron application from the command prompt with two command-line arguments:
shellapp.exe --url "https://example.com" --env production
In this example, --url
and --env
are custom command-line arguments, and their values are specified as "https://example.com"
and "production"
, respectively.
Within your Electron application, you can retrieve the command-line arguments using the process.argv
array. Here's an example of accessing the command-line arguments within your Electron application's main script:
javascript// Access command-line arguments
const args = process.argv.slice(2);
// Process the arguments
args.forEach((arg, index) => {
console.log(`Argument ${index + 1}: ${arg}`);
});
This code snippet retrieves the command-line arguments using process.argv
, excluding the first two default arguments (node
and the path to the main script). It then iterates through the arguments and logs them to the console.
By passing command-line arguments when launching the bundled Electron application and accessing them within your application's main script, you can utilize custom configurations or settings based on the provided arguments.