RunTool is blocking script/macro execution even on user tool output is not captured

RunTool is blocking script/macro execution even on user tool output is not captured

6
NewbieNewbie
6

    Dec 13, 2018#1

    I've tried to use RunTool in a script file, and it works. But the problem is that UltraEdit is waiting until the "tool" (a Windows application) is closed, even it is configured not to capture any output.

    For example my script opens a browser, now the message "Cancel Operation" is displayed in front of UltraEdit, and UltraEdit itself is blocked until I close the browser.

    Even when I click "Cancel" , the application stays blocked, until I close the "tool".

    Version is 25.10.0.62. (I can't update because I'm using a company installed version.)

    6,605547
    Grand MasterGrand Master
    6,605547

      Dec 13, 2018#2

      Have you selected for this tool in Tool Configuration on second tab Options as Program type Windows program?
      Best regards from an UC/UE/UES for Windows user from Austria

      6
      NewbieNewbie
      6

        Dec 14, 2018#3

        Yes, indeed I tried that. Did you manage to start an application by script without blocking UltraEdit?

        I'm now trying to create a little helper application which will start the target application and closes itself, to see if that will help achieve my goal. :)

          Dec 14, 2018#4

          Okay, it works that way, if I start my own application which starts another application, UltraEdit won't block anymore.

          I know there is UltraCompare, but in our company we have only the license for UltraEdit without it, but we do have Beyond Compare.

          So I did this little trick to be able to compare two opened files as easy as possible (the active document and the one next right to it).

          The script:

          Code: Select all

          // ----------------------------------------------------------------------------
          // Starting BeyondCompare via Helper Application
          // Using the first File to compare as the Active Document, and the second as the one after it.
          // ----------------------------------------------------------------------------
          
          var index;
          var first = false;
          var firstPath;
          var secondPath;
          
          for (index = 0; index < UltraEdit.document.length; index++) {
            if (UltraEdit.activeDocument.path === UltraEdit.document[index].path)
            {
              firstPath = UltraEdit.document[index].path;
              first = true;
            }
            else {
              if (first) {
                secondPath = UltraEdit.document[index].path;     
              }
              first = false;
            }
          }
          
          if (typeof firstPath != 'undefined' && typeof secondPath != 'undefined')
          {
            UltraEdit.newFile();
            UltraEdit.activeDocument.write('"'+firstPath+'" "'+secondPath+'"');  
            UltraEdit.activeDocument.selectLine();
            UltraEdit.runTool("BeyondCompare");
            UltraEdit.saveAs("D:\\temp\\edit1.txt");
            UltraEdit.closeFile("D:\\temp\\edit1.txt",2);
          }
          To make it works it's a little hack because the only parameter I found to populate from a script for RunTool was %sel%. So I had to open a new temporary file and also save it. (If you use this script change the path d:\\temp\\edit1.txt  to something which works for you.)

          Maybe someone has a better idea to handle this, but this is all I could figure out in the short time I was scripting with UltraEdit :)

          It would be better if runTool could also provide a parameter directly from a script.

          Anyway it works now perfectly for me.

          Here the C# Code for not provoking a block: (I'm starting this helper application, instead of BeyondCompare.exe directly):

          Code: Select all

          namespace StartBeyondCompare
          {
              static class Program
              {        
                  [STAThread]
                  static void Main(string[] args)
                  {
                      if (args.Length == 2)
                      {                
                          Process.Start(@"C:\Program Files (x86)\Beyond Compare 4\BCompare.exe", $"\"{args[0]}\" \"{args[1]}\"");
                      }            
                  }
              }
          }
          
          Also here it would be cool if UltraEdit would not block for Windows applications, or make a new script command.

          6,605547
          Grand MasterGrand Master
          6,605547

            Dec 14, 2018#5

            I was not aware that UltraEdit calls user tools with option set to Windows program in a blocking way from within a macro or script, but this is definitely the case as I could quickly verify with a macro and a script with UE v22.20.0.49 and v25.20.0.88. I have never run before a user tool from a macro or script which starts a Windows program. Those user tools configured by me which start a Windows GUI application are always started by me by key. The simple solution to workaround this issue is configuring in user tool DOS program (to start a command process) and insert on user tool command line at beginning start "". Now UltraEdit starts in background cmd.exe (as defined by environment variable ComSpec) which executes internal command start with an empty title and the Windows application to start and its arguments in a separate process as defined on command line for the user tool. cmd.exe exits immediately after start finished starting the application while the application is still running.

            Do you know that a different compare tool can be manually defined in INI file of UltraEdit for usage?

            See the topic External diff program / compare tool. I have tested Compare EXE=... with UE v25.20.0.88 and this setting is still working as described in my post from 2010-09-04. The INI file to edit is displayed at Advanced - Settings or Configuration - Application layout - Advanced.
            Best regards from an UC/UE/UES for Windows user from Austria

            6
            NewbieNewbie
            6

              Dec 20, 2018#6

              Yes, thanks for the hint with cmd, it should work also that way, and for users without Visual Studio or similar it's easier to achieve that way, for me it was easiest to create a little helper app. :)

              As for the integration through the .ini file, I saw this, but as I understood: it will not take the opened documents automatic, 
              but you have to select two files, once you open the Compare dialog.
              I like the solution to have the current file, and the one next right to it to be compared without a dialog at all.

              If I miss something, I'm eager to learn. :)

              6,605547
              Grand MasterGrand Master
              6,605547

                Dec 21, 2018#7

                UltraEdit selects automatically the active file as first file to compare and the previously active file as second file to compare on opening the Compare Files/Folders dialog for example with predefined hotkey Alt+F11. The user has the option to select for first and second file to compare a different opened file using the drop down list or click on the buttons ... to browse to files (or directories on using UltraCompare as comparison tool) not opened at all. But the user usually just hits next RETURN or ENTER to run the configured file comparison tool with the currently active and previously active file. The previously active file can be any opened file, not only the one right (or left) the active file. So it might be useful for you to add this line in INI file for usage of Compare Files/Folders in addition to your script if you want to run Beyond Compare with currently active file and previously active file or a completely different file instead of active file and the file right (or left) to active file in file tabs bar.

                I have also a suggestion for the script:

                Code: Select all

                // ----------------------------------------------------------------------------
                // Starting Beyond Compare via helper application with using active file
                // as first and the next or previous file as second file to compare.
                // ----------------------------------------------------------------------------
                
                if (UltraEdit.document.length >= 2) // Are at least two files opened?
                {
                   // Get document index of active file used as first file to compare.
                   var nDocIndex1 = UltraEdit.activeDocumentIdx;
                   // Set document index of next file for second file to compare.
                   var nDocIndex2 = nDocIndex1 + 1;
                   // If there is no more file next to active file, use the
                   // document index of previous file for second file to compare.
                   if (nDocIndex2 == UltraEdit.document.length) nDocIndex2 -= 2;
                
                   // Has the first file no real file name and also no real file extension?
                   var bFileNamed1 = !UltraEdit.document[nDocIndex1].isName("");
                   if (!bFileNamed1) bFileNamed1 = !UltraEdit.document[nDocIndex1].isExt("");
                   // Has the second file no real file name and also no real file extension?
                   var bFileNamed2 = !UltraEdit.document[nDocIndex2].isName("");
                   if (!bFileNamed2) bFileNamed2 = !UltraEdit.document[nDocIndex2].isExt("");
                
                   // Are both files named files and not new, unnamed files?
                   if (bFileNamed1 && bFileNamed2)
                   {
                      // Create a new file, write both full qualified file names enclosed
                      // in double quotes into this file, select the two argument strings,
                      // run the user tool and close the new file without saving it.
                      UltraEdit.newFile();
                      UltraEdit.insertMode();
                      if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                      else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                      UltraEdit.activeDocument.write('"'+UltraEdit.document[nDocIndex1].path+'" "'+UltraEdit.document[nDocIndex2].path+'"');
                      UltraEdit.activeDocument.selectToTop();
                      UltraEdit.runTool("BeyondCompare");
                      UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                   }
                   else
                   {
                      if (!bFileNamed1) UltraEdit.outputWindow.write("Error: File "+UltraEdit.document[nDocIndex1].path+" is a new, unnamed file.");
                      if (!bFileNamed2) UltraEdit.outputWindow.write("Error: File "+UltraEdit.document[nDocIndex2].path+" is a new, unnamed file.");
                      UltraEdit.outputWindow.showWindow(true);
                   }
                }
                else
                {
                   UltraEdit.outputWindow.write("Error: There must be opened at least two named files.");
                   UltraEdit.outputWindow.showWindow(true);
                }
                
                The script selects the file left to active file if the active file is the last one in documents array, i.e. is the last one on file tabs bar. The script also checks if both files are not new, unnamed files as in this case the files can't be compared with Beyond Compare without first saving the files in a directory.

                I have one more suggestion: The user tool runs the C# application written by you. So it would be also possible to pass the two full qualified file names from script via Windows clipboard to the C# application started as user tool. This would have the advantage that file names with one or more Unicode characters could be also passed to your self-coded application and there is not always a new file created temporarily.
                Best regards from an UC/UE/UES for Windows user from Austria