|
|
发表于 2008-5-28 10:21:43
|
显示全部楼层
Why Does My Executable Not Work When Using the Current VI's Path Constant?
Primary Software: LabVIEW Development Systems>>Full Development System
Primary Software Version: 8.2
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems>>Base Package, LabVIEW Development Systems>>Full Development System, LabVIEW Development Systems>>Professional Development System
Problem:
I am performing file I/O, and the file I want to open is always going to be in the same location as my VI. I'm using Current VI's Path so I can strip the VI name off the path and append the name of the file that I need to open. This works great in the development environment, but when I build my VI into an executable, the program can no longer find the file. Why is this happening?
Solution:
The problem is not with the Current VI's Path constant. The reason the file can't be found is because the path of a VI changes when you build it into an executable.
For example:
Assume the VI is called myapp.vi, and it exists in the C:\LabVIEW directory. Also assume that you have built an executable named myapp.exe, which also exists in the C:\LabVIEW directory. This is what the Current VI's Path function will return:
1) When running the VI in the LabVIEW development environment:
C:\LabVIEW\myapp.vi
2) When running the executable (myapp.exe):
C:\LabVIEW\myapp.exe\myapp.vi
So, when you have an executable, you actually need to strip the path twice to get to the C:\LabVIEW directory.
To find the running directory of an executable, instead use the Application»Directory Path property of the application itself (shown below).
Note that the leftmost VI is Open Application Reference, not Open VI Reference. Also, since this property searches for running LabVIEW executables, during development this property returns the path to your current instance of LabVIEW, usually C:\Program Files\National Instruments\LabVIEW 8.0. You can use the techniques described in the related links below to determine whether or not your current program is running as a VI in a development environment or as ab executable.
With LabVIEW 5.0 or earlier, a good workaround for this is to search the path for ".exe". If ".exe" is not present in the path, you only need to strip the path once to get to the desired directory. If ".exe" is present, you need to strip the path twice to get to the desired directory. The attached zip file has a VI that will do this. The VI has been built into an executable in LabVIEW 6.0 to show that the path is correct for both the VI and the executable. The executable was compiled in LabVIEW 6.0 so in order to run the executable, you will need the LabVIEW 6.0 run-time engine. If you want to run the executable in a different version of LabVIEW, you'll need to open the source code in the attached zip file and rebuild the executable in that version. The most current version of the LabVIEW run time engine can be found here (for Product Line select "LabVIEW", for Software select "LabVIEW Run Time Engine", then select the software version and operating system and hit "Go"). See the link below for more detailed information about the LabVIEW run time engine as well as a link to all previous versions fo the run time engine.
The VI can also be used as a subVI where you input the file name, and the VI returns the correct path. This path can then be passed on to File I/O functions, VI Server functions, Sound VIs, etc.
Related Links:
KnowledgeBase 3P88SPNQ: Which Run-Time Engine Do I Need for My LabVIEW Application Builder Executable?
KnowledgeBase 3OUH9J9E: How to Determine if an Application is Running as a VI or as an Executable |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|