Announcement

Collapse
No announcement yet.

Execute Commandline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Execute Commandline

    Hello,

    i am trying to execute a command on the commanline, "On Pre Install", but can't get it to work.
    Ist there a way to execute this command from within Setup Factory?
    Code:
    "%JAVA_HOME%\bin\jar.exe" xf pegasus4.jar config.properties
    It extracts one file from a jar.

    Greetings

  • #2
    Hello,

    Please provide the full code you are attempting to run, which is not working for you. Also, what is %JAVA_HOME%? Is that the environment variable (which may not have been defined), or a Session Variable you have set in your script? Also, in what folder the file "pegasus4.jar" is expected to be found? If you run this in On Pre Install, then it cannot be part of your application, because it was not deployed at this time...

    Ulrich

    Comment


    • #3
      Okey, so in more Detail: The code above can be pasted into the Power Shell or Windows-CMD as a command, and does exactly what it should.
      It extracts on file from an already existing .jar into the current directory.

      "%JAVA_HOME%" is indeed an invironment variable, for the location of the java sdk.
      The file "pegasus4".jar ist in the same folder where the setup is executed. Does this need to be fully specified!?
      "config.properties" ist the file that should be extracted from "pegasus4.jar", which ist done via the "jar.exe".

      This is supposed to be an update script, where there are already files. It is a workaround, until our developers have done some changes to our structure, so we don't have to extract this file anymore.

      The things i tried:
      - Putting the code into a file "extract.ps1" to execute that.
      Code:
       File.Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe","C:\\MovetaOnTest\\scripts\\extract.ps1","C:\\MovetaOnTest\\scripts",SW_SHOWNORMAL,false);
      Code:
      Shell.Execute(SessionVar.Expand("%AppFolder%").."\\scripts\\extract.ps1", "open", "", "", SW_SHOWNORMAL, false);
      -Excecuting the command directly.
      Code:
       Shell.Execute("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "open", '& "$env:JAVA_HOME\\bin\\jar.exe" uf pegasus4.jar config.properties', "", SW_SHOWNORMAL, false);
      Code:
      Shell.Execute("%JAVA_HOME%\\bin\\jar.exe", "open",  "uf pegasus4.jar config.properties", "", SW_SHOWNORMAL,false);
      - Excecuting without an environmental variable:
      Code:
      Shell.Execute("C:\\Program Files\\Java\\jdk1.8.0_351\\bin\\jar.exe", "open",  "uf pegasus4.jar config.properties", "", SW_SHOWNORMAL,false);

      Comment


      • #4
        Okay. If this pegasus4.jar file is in the same folder as the setup.exe, then this script should work for you. I have added quite a few lines for error checking and debugging, so you should have no difficulties in getting this working.

        Code:
        -- full path to the pegasus4.jar
        local sJAR = _SourceFolder .. "\\pegasus4.jar";
        if not File.DoesExist(sJAR) then
           Dialog.Message("Error", "Could not find " .. sJAR, MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
           Application.Exit(1);
        end
        
        -- full path to jar.exe
        local sJHome = os.getenv("JAVA_HOME");
        if (sJHome ~= nil) then
           sJava = sJHome .. "\\bin\\jar.exe";
           if not File.DoesExist(sJava) then
              Dialog.Message("Error", "Could not find " .. sJava, MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
              Application.Exit(1);
           end
        else
           Dialog.Message("Error", "JAVA_HOME is undefined", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);
           Application.Exit(1);
        end
        
        -- write line into log for debugging
        local sCmdline = "xf \"" .. sJAR .. "\" config.properties";
        SetupData.WriteToLogFile("Info\tExecuting: " .. sJava .. " " .. sCmdline .. "\r\n", true);
        -- execute jar to extract file
        nRes = File.Run(sJava, sCmdline, _SourceFolder, SW_SHOWNORMAL, true);
        error = Application.GetLastError();
        if (error ~= 0) then
           -- most likely something went wrong
           Dialog.Message("Error", _tblErrorMessages[error] .. "\r\r" .. sJava " .. returned " .. nRes, MB_OK, MB_ICONEXCLAMATION);
        end
        If you want to make this jar file part of your setup, place it into the Primer files, so it will be decompressed into the TEMP folder, and make the appropriate changes to the script in order to correct the path to the file (use Session Variables);

        Ulrich
        Attached Files

        Comment


        • #5
          Thanks a lot, this works

          You've been a tremendous help, have a nice day.

          Comment

          Working...
          X