Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

Running LabVIEW from PowerShell

Recently I was in a need to run LabVIEW VI from PowerShell while using Jenkins. The Jenkins part is pretty straightforward - you only need to install the PowerShell plugin for Jenkins and then you can run PowerShell command as a build step.

Running a VI from PS is simple, as long as you don't need to pass any commands. First of all, to make life easier add the LabVIEW executable path to the PATH environmental variable, and then just use:
Start LabVIEW C:\path\toYour\file.vi
but if you need to passy any commandline arguments to the VI (which was really important for me) trying to run the following command:
Start LabVIEW C:\path\toYour\file.vi -- arg1 arg2
resulted in an error, as LabVIEW could not find files arg1 nor arg2. To pass the exact command to the LabVIEW with arguments you have to make a clever use of apostrohes an quotation marks:
Start LabVIEW "C:\path\toYour\file.vi -- arg1 arg2"
If you want to get the commands from some variables things start to be even more complicated and you will have to use both - quotation marks and apostrophes in order to make something like:
Start LabVIEW "' + C:\path\toYour\file.vi -- arg1=" + $arg1 + " arg2=" + $arg2 + " logpath=" + $logpath + '.txt"
What I was doing was using Invoke-Expression from PS to run the command above, as it was easier than constructing the same command several times:
$code = 'Start LabVIEW "' + C:\path\toYour\file.vi -- arg1=" + $arg1 + " arg2=" + $arg2 + " logpath=" + $logpath + '.txt"'
Invoke-Expression $code
Why? mainly because you can e.g. use the Invoke-Expresson remotely on several machines over network etc. But this is totally different part of the story.

LabVIEWwise, parsing of the command line arguments is really simple, especially that I used the contruction of argument_name=argument_value, so I was able to parse them and get the values pretty straighforwards using a single case structure.

Don't be the product, buy the product!