Jump to content

using "system exec.vi" to get file opened in excel


Recommended Posts

NOTE: while typing this up i found my solution but decided to post anyway in case it may help someone else

 

I decided to quit beating my head off the keyboard and ask for help...I have a vi that will eventually be an .exe distributed across a variety of windows xp to windows 7 machines (32 and 64 bit). In this vi a bunch of data is saved to a .tsv file at C: i then need  to open the .tsv file in excel. After some searching i found System Exec.vi. it initially seemed to be my silver bullet because if i open command line in windows and type " excel.exe c:temp.tsv" Excel is opened (and this should work across different versions of Office). BUT with system exec.vi i get an error "Error 2 occurred at System Exec.vi Command was "excel.exe c:temp.tsv" Possible reason(s): LabVIEW: Memory is full." blah blah blah...

If i replace "excel.exe" with Notepad it opens the data no problem with notepad but i need it to be in Excel. i read about using "cmd /c" and attempted to no avail

 

Here's where i found my issue... it is "cmd /c" NOT "cmd c" ! so i used "cmd /c c:temp.tsv" and voila it opens with the default program for .tsv (which is obscure enough that i can make Excel a default on all of the computers in the building) for some reason cmd /c excel.exe does not work to open excel. i found this odd as excel.exe entered directly in the command line will open excel regardless of which version you have installed, but i believe i can live with this. 

Link to post
Share on other sites
Here's where i found my issue... it is "cmd /c" NOT "cmd c" ! so i used "cmd /c c:temp.tsv" and voila it opens with the default program for .tsv (which is obscure enough that i can make Excel a default on all of the computers in the building) for some reason cmd /c excel.exe does not work to open excel. i found this odd as excel.exe entered directly in the command line will open excel regardless of which version you have installed, but i believe i can live with this. 

 

Instead of using the command line, you can use the "Open URL in Default Browser" VI in LabVIEW.

You'll find this in the "Dialog and User interface"->"Help" palette (or in Quick drop).

 

This VI is polymorphic, and accepts a path or string as input. When given a path it opens the path using the default program for that file type. 

It even works with path to folders, allowing you to open a specific folder from your application.

 

/J

Link to post
Share on other sites
Instead of using the command line, you can use the "Open URL in Default Browser" VI in LabVIEW.

You'll find this in the "Dialog and User interface"->"Help" palette (or in Quick drop).

 

My new thing learned for the day, theres always something else I didn't know!

 

I don't know the exact windows in's and out's but you need the cmd /c because the system exec is the equivalent of the command going into the run... dialog NOT the command line. cmd /c is what causes it to execute as if from the command line.

Link to post
Share on other sites
I don't know the exact windows in's and out's but you need the cmd /c because the system exec is the equivalent of the command going into the run... dialog NOT the command line. cmd /c is what causes it to execute as if from the command line.

According to the the help, the "/c" adds the following "Carries out the command specified by string and then terminates".  If I run cmd, then type in "Copy ab.txt cd.txt" it will perform the copy and the command prompt window will remain open.  By performing a "cmd /c" it will cause the "cmd.exe" to close after the operation is complete.

Link to post
Share on other sites
  • 1 year later...

Using the .Net solution worked really to OPEN a (PDF) file, but I also need to automatically CLOSE the file afterwards.

 

I used the Reference from the START method  and then tried the CLOSE, DISPOSE, and KILL methods, but none of them actually closed the file.

 

Can .Net come to the rescue again - what am I doing wrong?  If there is no method of Closing the file I guess we could Kill the application (in this case Adobe Reader), but it's not as elegant.

 

Chris

Link to post
Share on other sites

Using the .Net solution worked really to OPEN a (PDF) file, but I also need to automatically CLOSE the file afterwards.

 

I used the Reference from the START method  and then tried the CLOSE, DISPOSE, and KILL methods, but none of them actually closed the file.

 

Can .Net come to the rescue again - what am I doing wrong?  If there is no method of Closing the file I guess we could Kill the application (in this case Adobe Reader), but it's not as elegant.

 

Chris

 

There is no general agreed method to close a process from another process. If it is a GUI application, sending it a WM_CLOSE message might work but for some applications just as likely might prompt with a dialog if you really want to close. Command line apps expect a ctrl-C to terminate prematurely but might disable the ctrl-C console handler for whatever obscure reason. 

 

The only way that will (almost) always work is to try to kill the process. Almost, because if the process is stuck in some call to kernel mode code it may never receive the kill signal.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Porter
      View File Robust CSV
      This package contains VIs for reading and writing to CSV files that follow the CSV format outlined in RFC-4180 (see http://tools.ietf.org/html/rfc4180). Using this package, you can properly import CSV files that were exported from spreadsheet programs such as Microsoft Excel, Open Office or LibreOffice Calc as well as export CSV files that will be compatible with any program capable of interpreting CSV files.
       
      This implementation of the CSV format is capable of handling escaped fields such as those containing commas (or other field delimiters), multiple lines, and double quotes.
       
      Notes:
      - Starting from V1.1.0, library files are located in "<LabVIEW>\vi.lib\LAVA\Robust CSV" and example is located in "<LabVIEW>\examples\LAVA\Robust CSV".
      Development version available on GitHub: https://github.com/rfporter/Robust-CSV
      Submitter Porter Submitted 02/21/2014 Category Database & File IO LabVIEW Version 8.6 License Type BSD (Most common)  
    • By Porter
      This package contains VIs for reading and writing to CSV files that follow the CSV format outlined in RFC-4180 (see http://tools.ietf.org/html/rfc4180). Using this package, you can properly import CSV files that were exported from spreadsheet programs such as Microsoft Excel, Open Office or LibreOffice Calc as well as export CSV files that will be compatible with any program capable of interpreting CSV files.
       
      This implementation of the CSV format is capable of handling escaped fields such as those containing commas (or other field delimiters), multiple lines, and double quotes.
       
      Notes:
      - Starting from V1.1.0, library files are located in "<LabVIEW>\vi.lib\LAVA\Robust CSV" and example is located in "<LabVIEW>\examples\LAVA\Robust CSV".
      Development version available on GitHub: https://github.com/rfporter/Robust-CSV
    • By Aishwarya Saravanan
      My project involves designing a front end for a synchronous generator using LabVIEW.   It is actually data acquisition and display of signals in a file.   The problem I face when building a program is that:   1)the sampling rate is set to 100 samples with 1 kHz sampling frequency.These signals are generated by daq assistant and i have used merge signals to merge these signals from daq assistant as well  as signals from other radio buttons and Boolean as well. The problem is that when written on a file I am able to see only one instance of Boolean status for every 100 samples daq assistant creates.   2) now iam able to write only 0/1 as status of Boolean in the file.How will I write on /off into file?

    • By Gab
      Hello,
      Is it possble to put signatureline into excel footer using Active X ?
    • By Paul Liu
      Hi All,
      I am a new user to LabView and this is my first project using it. The project requires me to read a massive spreadsheet from Excel into LabView and then allowing the user to do the following:
      - Select which columns to plot against the first column
      - Use a cursor to select a portion of the spreadsheet: the Vi will then average the selected data by column (in other words, if the user selects data across multiple columns, the program will average data in each column separately). Then write the averages to the csv file.
      So far, I have the spreadsheet read into a table as strings (because the first row of the spreadsheet is words). I have spent a lot of time searching how to allow the user to select data on the table to perform operations on, but to no avail. I am hoping you guys could give me some insight on how to tackle this project.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.