03-09-2017 04:42 AM
As part of CI (Continuous Integration) with LabVIEW. We are trying to start a VI from a powershell script.
Starting Labview, opening the VI is no problem.
We are having problems sending over the Arguments to our VI.
In a batch script this was no problem using code like this:
START "Labview" "C:\Program Files (x86)\National Instruments\LabVIEW 2015\LabVIEW.exe" "C:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Application Control\VI Server\Passing Command Line Parameters\Command Line Target.vi" -- /number:0 "/string:" /boolean:FALSE
Now when Using Powershell none of similar actions seem to work, like this:
$Arguments=@(" -- ","/number:0","/string:","/boolean:FALSE")
& "C:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Application Control\VI Server\Passing Command Line Parameters\Command Line Target.vi" -ArgumentList $Arguments
Is there a way to send arguments to LabVIEW with Powershell?
Solved! Go to Solution.
03-09-2017 08:51 AM
I think the problem is that you are confusing LabVIEW, the Language, with LabVIEW, the Development System. When you start LabVIEW to do Development, you can start it three ways "manually" -- double-click the LabVIEW Icon on your desktop, drag a VI onto that Icon, or double-click the a LabVIEW .vi (or .lvproj) file. The first one opens LabVIEW with no code loaded, the other two load code.
Then what? Then you type on your keyboard or move your mouse to develop your code. If you want to run your code in Development Mode, you click on the Run button (or type maybe Ctrl-R -- I never do this except by accident ...).
I could see using PowerShell to open LabVIEW with a VI ready to "manually" edit, but if I wanted, instead, to execute the LabVIEW code, I wouldn't work in Development Mode, but would use LabVIEW to build an Executable (a.k.a. an Application). Now you have a .EXE, "My Application", that has Inputs and Outputs and you can Powershell to your heart's content.
Bob Schor
03-09-2017 09:10 AM
What Bob said is right. The solution that works for most people is they set the controls to the values they want, right click and make them the default, then change the VI to run when opened. Then if you call it to open in LabVIEW using the command line, it will run with the values saved. You could get crazy and make a nice solution to make it do what you want but there would be some extra work. What I'm thinking you could do is write a LabVIEW EXE that takes command line arguments (settings are in the application builder) and then part of the arguments is the VI that needs to be opened and the control values that need to be set. Then that EXE can open a reference to a LabVIEW application instance, perform the open VI reference, set the VI controls, and then run it through invoke nodes. All possible but again the solution most people do is just run when opened using default values. You could cut out the middle man and make your VI into an EXE that accepts command line arguments as well but as source a VI doesn't get arguments, it isn't an application it is source code.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
03-09-2017 09:20 AM - edited 03-09-2017 09:21 AM
This would work if you were using a single version of labview. in our case, we are building different projects on different versions of labview from 2014 till 2016. We don't want to build an "continuous integration" executable (which can build/test/package the given project) because we want to use a single project which handles this. and maintain this code in a single project. For our continuous integration project we use the project which is developed by a team from NI, and this project can be found at this link.
So let's get back to our problem. when starting a vi in the development environment from a batch script with arguments, the code above is working just fine. because of limitations of batch scripts we want to use Powershell. but when we want to send arguments like described above, it doesn't work.
Does anyone have any experience with opening vi's with a powershell script and handling arguments from powershell?
03-09-2017 09:50 AM - edited 03-09-2017 09:53 AM
@Maarten1202 wrote:
This would work if you were using a single version of labview. in our case, we are building different projects on different versions of labview from 2014 till 2016.
Oh okay well my solution with opening application references, and VI references in that application reference is still valid. Think about VIPM. It has multiple versions of LabVIEW to manage, and needs to be able to install packages (which may require running a VI) in a specific installed version of LabVIEW. Using application references (from an open VI Server port) is how it does it. It is also how my LabVIEW Tray Launcher does it. It is a tool that allows you to open a VI in a version of LabVIEW showing you what ones are compatible with the VI, and what ones are currently running.
So you would need to build a single EXE that accepts command line parameters that are things like path to the VI, version of LabVIEW to run it in, and control names and their values. Then the EXE would open a reference to that version of LabVIEW, open that VI based on the path, set the control values, and run it. Not simple but do able, and it wouldn't be version dependent just like how my application works can be ran in the 2011 run time engine, but work with (I think) all versions of LabVIEW that support the VI server API.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
03-09-2017 10:12 AM - edited 03-09-2017 10:13 AM
Hello,
I can see your suggestion.
but i think it won't help our problem. As the problem is not: starting the right version, but sending over the arguments.
In the image below you can see our current setup
The red circle we want to get rid of. But then we need a way to pass the arguments form Powershell to the VI directly.(Blue line)
In batch currently this is working. so we thought this is possible in Powershell. but it looks like labview is not accepting our arguments when it is not from batch.
If sending arguments to EXE will work, is something i will test tomorrow.
03-09-2017 10:36 AM - edited 03-09-2017 10:37 AM
@Maarten1202 wrote:
but i think it won't help our problem. As the problem is not: starting the right version, but sending over the arguments.
This is all over VI server, you'll have a reference to the VI, the VI's front panel, block diagram, controls, just about everything you can do as a developer you'll be able to do with VI scripting and VI server. Send arguments to the EXE, then have the EXE set the control values (using the VI reference) before running.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
03-10-2017 03:21 AM
So you are tying to get rid of the mediator which is now a batch file. This batch file starts the VI with some arguments and you want to do this is the same powershell script which is called by jenkins? But you've encountered problems with sending arguments from powershell? So I recon you've already checked this page out?
http://zone.ni.com/reference/en-XX/help/371361K-01/lvprop/app_command_line_args/
So the code you are using in powershell is this:
$Arguments=@(" -- ","/number:0","/string:","/boolean:FALSE") & "C:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Application Control\VI Server\Passing Command Line Parameters\Command Line Target.vi" -ArgumentList $Arguments
So the problem is the way powershell sends arguments to labview.
To hack this problem you could try to run cmd in powershell with the following line:
cmd /c '"START "Labview" "C:\Program Files (x86)\National Instruments\LabVIEW 2015\LabVIEW.exe" "C:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Application Control\VI Server\Passing Command Line Parameters\Command Line Target.vi" -- /number:0 "/string:" /boolean:FALSE"'
03-27-2017 08:14 AM
I have encountered the same problem recently - I want to run a specific VI with command line parameters from PowerShell.
The VI is autostarting after being opened, reads the command line arguments and acts accordingly - this runs flawlessly when run from CMD.
After running in PowerShell:
LabVIEW C:\Project\MyPrecious.vi -- arg1 arg2
I start the LV with my precious VI but it does not read the arguments; it rather tries do run arg1 file (that obviously does not exist) in LV. How to make such thing work in PS natively?
03-28-2017 03:32 AM
Hello,
I tried most thing natively in PS. but nothing worked. indeed passing arguments was never a succes.
The only solution as mentioned above was using a cmd line expression in powershell.
in this case you don't need an external Batch script.
The line in powershell i use now is:
cmd /c "START "Labview" ""$LV"" ""$VI"" -- ""$1"" ""$2"" ""$3"" ""$4"" ""$5"" ""$6"" ""$7"" "
In this case the variavbles are used as:
$LV is the path to the LabVIEW.exe in Program Files.
$VI is the path to the executing .vi
$1-7 are the arguments
As far as i tried all the quotes are needed.
If you find any better solution for the quotes let me know.