Announcement

Collapse
No announcement yet.

File.Run command with custom variable in argument field

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

  • File.Run command with custom variable in argument field

    Hi!

    I'm trying to code the following action.

    First On Startup I setup the following variable:
    SessionVar.Set("%AppFolder%", Registry.GetValue(HKEY_CURRENT_USER, "SOFTWARE\\Lockheed Martin\\Prepar3D v4", "AppPath", true));

    Then On Shutdown I'm trying to run the application with the following argument:
    result = File.Run(SessionVar.Expand("%AppFolder%\\Prepar3D. exe"), "-Configure: Category=Add-on Package, Operation=Add, Title=Test#1, Path=%AppFolder%\\Ecosystem\\Test#1\Product#1", "", SW_SHOWNORMAL, false);

    The problem is that the Path is not called correctly as I'm unable/don't know how to insert a variable to it.

    I'd be grateful for any suggestions on how this could be done correctly.

    Cheers!

  • #2
    You need to use SessionVar.Expand() in the second argument as well to actually expand the contents of %AppFolder%.

    Ulrich

    Comment


    • #3
      Hi Ulrich,

      Thank you for your reply. I've been trying to do so however I can't proceed further.

      This is example of my script:

      result = File.Run(SessionVar.Expand("%AppFolder%\\Prepar3D. exe"), "-Configure: Category=Add-on Package, Operation=Add, Title=Test#1, Path= result = SessionVar.Expand("%AppFolder%")\\Ecosystem\\Test# 1\Product#1", "", SW_SHOWNORMAL, false);

      or alternatively

      result = File.Run(SessionVar.Expand("%AppFolder%\\Prepar3D. exe"), "-Configure: Category=Add-on Package, Operation=Add, Title=Test#1, Path= result = SessionVar.Expand("%AppFolder%\\Ecosystem\\Test#1\ Product#1")", "", SW_SHOWNORMAL, false);

      Regards

      Comment


      • #4
        When something does not work as expected, try to break it down into smaller parts, and use the log file to write the results, as this will help in debugging scripting errors.
        I have rewritten the code as below, of course this is untested, but looks much more likely to work.

        Code:
        local sProg = SessionVar.Expand("%AppFolder%\\Prepar3D.exe");
        local sArgs = SessionVar.Expand("-Configure: Category=Add-on Package, Operation=Add, Title=Test#1, Path=\"%AppFolder%\\Ecosystem\\Test#1\\Product#1\"");
        SetupData.WriteToLogFile("Info\tWill attempt to run " .. sProg .. " " .. sArgs .. "\r\n", true);
        result = File.Run(sProg, sArgs, "", SW_SHOWNORMAL, false);
        If you get errors, check the log file for mistakes.

        Ulrich
        Last edited by Ulrich; 09-01-2019, 10:37 AM.

        Comment

        Working...
        X