From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a package for parsing command line flags?

Solved!
Go to solution

I'm building an application which runs as a standalone executable. I want to optionally start the program with command line arguments, but I don't want to have to write an entire parser if something already exists that I just don't know about. And I don't hate myself enough to regex one. I've downloaded G CLI toolkit but I believe I misunderstood what this toolkit is, as it seems to be a way to run labview as a CLI and not a way to make a labview CLI program. Once my program is launched, I don't need to continue interacting with it via command line. This is just to launch it.

 

Functionality that would be preferable (although if something simpler exists, I'm happy to tailor my application to it):

flags: -e --example 

key value pairs: --foo=bar OR --foo bar (where the argument after the space is the value)

string handling: --foo="bar with some spaces"

 

I can't be the first person to want this, right?

 

0 Kudos
Message 1 of 4
(1,237 Views)

Yes, there is. Drop a property node down and select App->Command Line Arguments". This will give you an array of the command line arguments passed to the application. The first entry is the executable name. The following are the list of arguments as they appear on the command line. You will need to parse this list and how you do so will depend on your format. For example, if your format is "--foo=bar", they entire argument will be in one element of the array. If your format is "--foo bar", this will appear in two consecutive elements in the array. It would be up to you to choose the appropriate format for your arguments as well as the proper parsing of the list to ensure list is handled properly, i.e. enforcing required and optional parameters, detecting if an argument is missing a parameter, etc.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 4
(1,187 Views)
Solution
Accepted by topic author Nokaroa

@Mark_Yedinak wrote:

...You will need to parse this list and how you do so will depend on your format.  ... It would be up to you to choose the appropriate format for your arguments as well as the proper parsing of the list to ensure list is handled properly, i.e. enforcing required and optional parameters, detecting if an argument is missing a parameter, etc.


Okay, so the answer is "no, there is not".

0 Kudos
Message 3 of 4
(1,178 Views)
Solution
Accepted by topic author Nokaroa

Actually I was wrong! The G CLI Toolkit DOES have what I need, but I was having issues installing it so I couldn't find the right VIs, and I couldn't find good documentation at the time. I answered my own question and I was wrong....

 

For anyone in the future wondering, it's under Connectivity -> G CLI -> Parse Arguments. That's totally on me...

0 Kudos
Message 4 of 4
(1,082 Views)