3 Replies Latest reply on Apr 28, 2011 11:54 AM by Jeremy Schmidt

    execute command transition parameters

    Jeremy Schmidt

      How do you pass a parameter with a space in the string to an executable in a transition?  I have tried putting single quotes and double quotes around the parameter, but it doesn't seem to matter.  It seems to split the string into mulitple parameters.  For example, I wanted to start the application C:\Program Files\Test\Program.exe, so my command line was: C:\Program Files\Test\Program.exe.  It tried to open C:\Program.  So I moved the program to C:\Test\Program.exe and everything worked fine.  Then I tried to pass the preset "File Path" parameter to my executable.  The filepath is C:\EPDM\New Folder\testfile.txt.  It passes "C:\EPDM\New" as the first parameter and "Folder\testfile.txt" as the second parameter.  If I run it from the command prompt with each parameter surrounded by double quotes, I have no issues.  What is going on?

        • Re: execute command transition parameters
          Jeff Sweeney

          Put the executable inside of quotes and the parameters inside of quotes:

           

          e.g. "C:\Program Files (x86)\Microsoft Office\Office12\excel.exe" "c:\cache\Book1.xlsx"

          Execute.JPG

          • Re: execute command transition parameters
            Jim Sculley

            I've done some simple testing and it appears that EPDM does very little to handle spaces in this situation.  If you want to see what is happening behind the scenes, log in to the database server and look at the 'Message' column of the dbo.TransitionActions table.  For my tests I tried to start Firefox passing the transitioning file (a text file) as a parameter.  The paths to Firefox and the file both contain spaces.  Firefox is in C:\Program Files (x86)\Mozilla Firefox and the test file is in C:\_EPDM\Admin\Forum Tests

             

            If I do the straightforward thing, ignoring spaces, and using the ProgramFiles(x86) and FilePath variables in my Execute Command action, the 'Message' stored in the database is:


            0|%Env_ProgramFiles(x86)%\Mozilla Firefox\firefox.exe %FilePath%

             

            It is clear from this that SolidWorks doesn't do any space related transformations before stuffing this in the database.  The space between Mozilla and Firefox is passed as-is.

             

            If I try to transition a file, I get the error message stating Windows cannot find 'C:\Program'.  Clearly, EPDM is not handling spaces inside the environment variable (ProgramFiles(x86)), before passing the command along to Windows.  So, I surround the environment variable with double quotes.  The database now holds this:

             

            0|"%Env_ProgramFiles(x86)%"\Mozilla Firefox\firefox.exe %FilePath%

             

            When I transition a file, Windows opens a File Explorer window on the C:\Prrogram Files (x86) directory.  So it appears to now be choking on the space between Mozilla and Firefox.

             

            I edit the action so that there is a double quote before the environment variable and after Firefox.  The database now looks like this:

             

            0|"%Env_ProgramFiles(x86)%\Mozilla Firefox"\firefox.exe %FilePath%

             

            When I transition a file, Windows opens a File Explorer window on the Mozilla Firefox directory.  So it seems to ignore anything after the closing double quote and opens a file explorer window on what's inside the double quotes.

             

            I edit the action once more, to surround the entire command in double quotes.  The database is now:

             

            0|"%Env_ProgramFiles(x86)%\Mozilla Firefox\firefox.exe" %FilePath%

             

            On transitioning a file, Firefox starts and tries to open two locations:

             

            file:///C:/_EPDM/Admin/Forum

            http://www.tests.com/test.txt

             

            Clearly, Firefox has seen the FilePath variable as two distinct files, split on the space between Forum and Tests.

             

            If I surround the FilePath variable in double quotes, the database now contains:

             

            0|"%Env_ProgramFiles(x86)%\Mozilla Firefox\firefox.exe" "%FilePath%"

             

            Transitioning the file now produces the desired result.  Firefox opens with the transitioned file(s) displayed.

             

            Taking it one step further, I can pass a second parameter to Firefox, asking it to open each file in a new window.  If I add the -new-window argument inside the double quotes along with FilePath, the database looks like this:

             

            0|"%Env_ProgramFiles(x86)%\Mozilla Firefox\firefox.exe" "-new-window %FilePath%"

             

            Transitioning a file does not work  properly.  A new window is opened but it is empty.  The second parameter (FilePath) has been lost somewhere.  Putting each parameter in double quotes makes the database look like this:

             

            0|"%Env_ProgramFiles(x86)%\Mozilla Firefox\firefox.exe" "-new-window %FilePath%"

             

            and everything works as it should.  The file is opened in a new Firefox window.  Transitioning multiple files also works as expected.

             

            So, it appears that the best approach is to surround the entire command in double quotes and each parameter in its own double quotes.

             

            Jim S.