Pass Arguments to Code via Application Shortcut
We recently had a requirement on a test station to enable a different configuration file to be used by a LabVIEW application due to a parameter in the configuration file being different depending on the product the application was being used for. We were constrained to the fact we couldn't create a seperate physical implementation of the test station and we didn't want to go down the route of hardcoding anything! So we decided to utilise the cammand line and have two shortcuts to our application, one for product 1 and one for product 2 and here's how we implemented it.
The information that we needed to pass into our LabVIEW application was the location of the configuration file for the product being tested. For this we created two network drives on the PC for where each of the configuration files were located. Next step pass that information into the executable via the shortcut.
When shortcuts are created for applications you specify the path to where the application resides, including the name of the application. To allow information to be passed in we can use arguments that are added onto the end of the path, this article goes into a bit of detail on this. For our application we specified the argument as detailed below. In the properties of the shortcut, we add '-c', which is the identifier for the argument. Following that we added the value of the argument, which in our case is the path relative to the configuration file for the product the shortcut is for. Now on to the LabVIEW side!
To read the argument from the shortcut there is a relative straightforward implmentation in LabVIEW. We use a property node linked to the application and select the Command Line Arguments as the property to read. This gives us a string array out that contains all arguments, in some cases you may have more than one. We interegate the array to find our '-c' argument and retrieve the value of the argument.
A nice and simple solution!
If you have something to shout about related to LabVIEW or software development, get in touch, because we would love to hear about it at our User Group (MLUG)!
Back to Blog listings