How to retreive command line arguments
See original GitHub issueI’m working on an application right now where I’d like the user to be able to launch the application via a terminal, but also be able to specify a default file to load. e.g. myApp image.png
I’m wondering if there is an easy way for my application to retrieve the command line argument that were passed into it at this part:
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); // `args` comes from `Program.cs`'s `Main()`
E.g. In my App
’s code, I’d like to be able to retreive those args and parse them to find an initial file:
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
// Get those `args` somewhere around here and then pass them into a function in the `DataContext`
}
base.OnFrameworkInitializationCompleted();
}
I saw that there was this entry on the wiki: https://github.com/AvaloniaUI/Avalonia/wiki/Application-lifetimes#manual-lifetime-management
AFAICT, it seems like the only way to pass those command line args off to my app’s code. Unless there is another way?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How do I find out command line arguments of a running ...
Right click on any column and select "Show Columns" and then check "Command Line Arguments" option > Click OK. Then select the process...
Read more >windows - How to get list of arguments?
%0 - the command used to call the batch file (could be foo , ..\foo , c:\bats\foo.bat , etc.) %1 is the first...
Read more >Command Line Arguments in C/C++
To pass command-line arguments, we typically define main() with two arguments: the first argument is the number of command-line arguments and ...
Read more >How to Get the Command Line Args Passed to a Running ...
1. Introduction · 2. Finding the PID of a Process · 3. Using the ps Command to Get Arguments Using PID · 4....
Read more >Environment.GetCommandLineArgs Method (System)
Returns a string array containing the command-line arguments for the ... To obtain the command line as a single string, use the CommandLine...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Nikhilsp I put this in App.axaml.cs:
@out4blood88 Your code works but the designer previewer of the .axaml files stops working. It just remains stuck on “The designer is loading”.