11 Replies Latest reply on Feb 25, 2013 12:17 PM by philmodjunk

    Button that opens a file with arguments

    JoshSturtevant

      Title

      Button that opens a file with arguments

      Post

           I am trying to open a file and pass along 2 fields that are in the current records to use as arguments for the file. I dont know if this is possiable

            

           I have 2 records on is TVUser and the others is TVPass

            

           I want to open file TV.exe with arguments of TVUser and TVPass

            

           Basically I want it to be "TV.exe -i TVUser --Password TVPass"

            

           so that way it opens up the exe witht he correct username and password based on what record I am currently on.

            

           is this possiable?

        • 1. Re: Button that opens a file with arguments
          philmodjunk

               Can you construct a windows command line that opens this application with the specified arguments?

               Here is an example of a script that uses a command line to create a new directory on the User's desktop that you may be able to use as a model:

               Set Variable [ $dirName; Value:"EVO PlaceHolders" ]
               Set Variable [ $desktopUse; Value:Substitute ( "/" & Get ( DesktopPath ); [ "//" ; "" ]; [ "/" ; "\\" ]) ]
               Send Event [ open document/application; "cmd.exe /C MKDIR " & Quote ( $desktopUse & $dirName & "\\" ) ]

          • 2. Re: Button that opens a file with arguments
            JoshSturtevant

                 Ok i get the idea of what you are trying to do and the concept works but I cant get it to work in FileMaker, I havnt done much with the send event command so I am a little confused on how to get it to work properly. Listen below is my script and hopefully you can let me know where I am going wrong.

                  

                 Set Variable [$TVUser; Value:locations::TVUser

                 Set Variable [$TVPass; Value:locations::TVPass

                 Set Variable [$TVPath; Value:"C:\Program Files (x86)\TeamViewer\Version7\TeamViewer.exe"

                 Send Event ["aevt"; "odoc"; ""cmd.exe" & Quote($TVPath * " -i " & $TVUser & " --Password " & $TVPass)"]

            • 3. Re: Button that opens a file with arguments
              philmodjunk

                   The text you are assigning to $TVPath won't evaluate as you expect. The \ character has special meaning in FileMaker quoted text. It's the "escape" character used to tell FileMaker to use the character immediately after it as a literal character and not a quotation mark. Thus:

                   "This is \"quoted text\""

                   evaluates as:

                   This is "quoted text".

                   To get the \ to be treated as a \ and not the escape character, you have to escape the escape character and use:

                   "C:\\Program Files (x86)\\TeamViewer\\Version7\\TeamViewer.exe"

              • 4. Re: Button that opens a file with arguments
                JoshSturtevant

                     I understand what you are saying about the / but i feel i must still hav esomething off on my script... I added the extra \ to the path but when I run the script above with the extra all it does is open up cmd.exe and that is it.

                      

                     I appreciate your help with the issue also

                • 5. Re: Button that opens a file with arguments
                  philmodjunk

                       If you open a command window and manually enter this data (without the extra \ characters), does it work?

                       One drawback to this method is that you can't see any error messages returned that might clue you in to what needs to be modified.

                       I usually execute command lines from a batch file created and performed via Export Records. That allows me to append a "pause" command line to the end of the command or commands whenever the command does not produce the desired result.

                       This method requires putting the entire command line into a text field--one such record for every command line that needs to be exported.

                  • 6. Re: Button that opens a file with arguments
                    JoshSturtevant

                         It will run if I add quotes in command window around the path... It errors on the spaces in program files if i dont added quotes.

                          

                         I am just not sure if it isnt possiable to do what I want cause all that happens when I run script is command program comes up  as if i typed in cmd.exe in run and that is it

                    • 7. Re: Button that opens a file with arguments
                      philmodjunk

                           If you can get it to work from the command window, this can be done from FileMaker. Some small detail in what you are ouputting is not working. The fact that you can't see any error messages nor what exact text was used as the arguments is why I prefer to generate and execute a batch file as I mentioned in my previous post.

                           I think I spotted some issues with this step:

                           Send Event ["aevt"; "odoc"; ""cmd.exe" & Quote($TVPath * " -i " & $TVUser & " --Password " & $TVPass)"]

                           Change it to be:

                           Send Event ["aevt"; "odoc"; "cmd.exe " & Quote($TVPath *) & " -i " & $TVUser & " --Password " & $TVPass ]

                      • 8. Re: Button that opens a file with arguments
                        JoshSturtevant

                             So how would doing it the batch file way work?

                              

                             Cause no matter what I do to code it just pops up the command prompt and that just stays up, nothing seems to happen so i dont know if it just isnt running anything after or what.

                        • 9. Re: Button that opens a file with arguments
                          philmodjunk

                               Put the entire command line in a single text field of a table of command line records. This can be done with a script or perhaps it can be defined as a calculation field.

                               Use export records to export  this one record as text to a file with a name ending in .BAT.

                               Select the "open" option so that the file is automatically opened after export. You can export the file to temporary items so that you don't clutter up you computer with a lot of text files.

                               To include a "pause" in the process, add a second record to this table with Pause as the command line.

                          • 10. Re: Button that opens a file with arguments
                            JoshSturtevant

                                 Guess I have one more question about the batch file, I did the export fields and the problem with this is it exports all the records under 1 field... i only want the current records field to be sent to the batch file.

                                  

                                 i tried export field contents and when it creates the bat file the batch file wont work (though it will if I only have 1 record total in exports records)

                                  

                                 do you know what I can do to fix this?

                            • 11. Re: Button that opens a file with arguments
                              philmodjunk

                                   Export Field Contents uses different text encoding for returns that screws up multi-line commands. (I tried that first when I first figured this out for my own recent projects.)

                                   Export Records exports your currnent found set of records so make sure that only the records you want to have in the batch file are in the current found set before you export them. And you can use field mapping to restrict the exported data to that single text field.

                                   I've devised a pair of tables with scripts, that I hope to share here in forum in the near future. One table has one record for each batch file with a name and ID number for that batch file. A related table lists all the commands for each batch file. I then have a script that can find all the command line records for a given batch file, sorts them in  correct order, loops through them to update data from a list of values passed as a script parameter and then exports the records to execute the batch file.

                                   And I can execute VBS scripts from the same exact pair of tables as long as my code puts the correct file extension on the file created by the records export.