Script specified on command line executed twice (fixed in UE v16.00.0.1036)

Script specified on command line executed twice (fixed in UE v16.00.0.1036)

5
NewbieNewbie
5

    Mar 12, 2010#1

    Is there some configuration value that can be set in a script to avoid creating a backup file when "saveAs" is used?

    That is, is there some variable that can be set that is equivalent to the configuration setting "File handling -> Backup -> No backup" radio button in the GUI?

    I want to save a file with a new name, but not have a .bak or other file also created.

    Thanks, Mike

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 12, 2010#2

      A backup file is created when using Save As only when the file already exists and the backup configuration is enabled. It does not matter how the Save As command is called - by the user, from within a script of from within a macro. There is no setting, property or parameter which can be used in scripts to control creation of the backup file when using Save As and file already exists.

      You can configure a user tool containing the command line del "%f.bak" or del "%p%n.bak" and call that user tool from within the script after saving the file with a new name.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Mar 12, 2010#3

        Thanks for the information.

        Perhaps this is my bigger problem: My Windows batch file and .js script file seem to be processing the input file twice.

        Here's the command line in the batch file:
        uedit32 /fni "C:\Projects\myfile.txt" /s="C:\Projects\editscript.js"

        (By leaving off the ,e in the /s parameter I thought I could see better what is happening by not closing UltraEdit. The ,e doesn't seem to affect the script processing, anyway.)

        myfile.txt is processed twice.

        If the editscript.js file executes

        Code: Select all

            UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
            UltraEdit.activeDocument.findReplace.replaceAll=true;
            UltraEdit.activeDocument.top();
            UltraEdit.activeDocument.write("A new line" + "\r\n");
        ...
            UltraEdit.activeDocument.save();
            UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
        then "A new line" is written twice at the beginning of the second instance of the file.

        Why would myfile.txt be processed twice by UltraEdit?

        What am I doing (or not doing) that causes this?

        And what does the '2' argument to closeFile mean?

        Thanks again for your trouble.

        Sincerely, Mike

        6,675585
        Grand MasterGrand Master
        6,675585

          Mar 12, 2010#4

          Mike wrote:And what does the '2' argument to closeFile mean?
          Closing the file without save as documented in help of UltraEdit on page Scripting commands. I don't know why you have the inserted lined twice in your file, not with that code snippet.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Mar 12, 2010#5

            Thank you for your patience. I'll remember to check the UltraEdit Help for script commands.

            Here is a simplified set of files.

            testfile.txt contains:

            Code: Select all

            This is the only line in the file.
            double-write.bat contains:

            Code: Select all

            uedit32 /fni  "C:\Projects\testfile.txt"  /s="C:\Projects\double-write.js"
            double-write.js contains as the only 2 lines:

            Code: Select all

            UltraEdit.activeDocument.top();
            UltraEdit.activeDocument.write("A new line" + "\r\n");
            Running the .bat file allows testfile.txt to remain open in UltraEdit with this content:

            Code: Select all

            A new line
            A new line
            This is the only line in the file.
            It appears that the file is either edited twice, or the file is opened twice and edited both times.

            No other instance of UltraEdit was running when the .bat file was executed.

            Any ideas?

            Maybe I should also say that I'm using version 15.20.0.1017 of UltraEdit.

            I'll also point out that if "double-write.js" is added as a script within UltraEdit using the Scripting -> Scripts... menu item, the script only inserts "A new line" once in the file being edited, not twice.

            Is there something about using a batch file, or /fni, or /s that causes double processing of the file?

            Thanks again,
            Mike

            262
            MasterMaster
            262

              Mar 13, 2010#6

              Using the very latest version UE 16.00.0.1029 (on Win Vista Home Premium, SP2) I get the same result. The script is invoked twice when starting the script as in your example:

              Code: Select all

              C:\temp>uedit32 /fni temp.txt /s=temp.js
              and when I add ,e UE crashes:

              Code: Select all

              C:\temp>uedit32 /fni temp.txt /s,e=temp.js
              Tried adding UltraEdit.save(); to the script. Same result: crash - but no dump file "as usual" ?!.

              Please report the problem to IDM support - click "mail us directly" at the top of this page to get the e-mail address.

              6,675585
              Grand MasterGrand Master
              6,675585

                Mar 14, 2010#7

                I tried the same with UE v16.00.0.1029.

                With testfile.txt containing only the line This is the only line in the file.
                and the script file double-write.js containing only the line UltraEdit.activeDocument.write("A new line\r\n");
                and using the command line uedit32.exe /fni testfile.txt /s=double-write.js
                the line is indeed inserted twice and I could see with Filemon that the script is opened/read (executed) twice.

                But using command line uedit32.exe /fni testfile.txt /s,e=double-write.js produced the correct result. With the single line script I was asked to save the modified file containing only 1 inserted line and independent of my choice UltraEdit exited correct and the file content was correct depending on my choice. With command UltraEdit.save(); as additional command in the script the execution worked too. So no crash with my settings.

                But the double execution of the script when not exiting UltraEdit is definitely a bug of UltraEdit. I could reproduce it with all versions of UltraEdit down to v14.00b+1. UE v13.20a+1 works correct. So I think this problem exists since v14.00 and nobody has detected this bug until now. I think the reason why it is only now detected is that most scripts executed via command line save and close the file(s) after modification and exit UltraEdit. Really strange.

                Mike, please report this bug to IDM support by email or post if I should do it. Thanks.
                Best regards from an UC/UE/UES for Windows user from Austria

                5
                NewbieNewbie
                5

                  Mar 15, 2010#8

                  I never did get a crash from UltraEdit.

                  A little more testing after my previous posts indicated that the ",e" prevented the double editing.

                  Use of

                  Code: Select all

                  UltraEdit.saveAs(newFile);
                  UltraEdit.closeFile(newFile,2);
                  saved the file fine.

                  Use of closeFile without the ",e" on the command line allowed UltraEdit to stay open, but prevented the double editing (if I remember correctly). I had originally omitted the ",e" so that I could see the file edits during development without having to reopen the file.

                  Anyway, I've change the script to use ",e" and to save the file, and things are working well, now.

                  --> Mofi: Would you please submit the problem to IDM? With your past experience, they'll probably accept your report with more authority than mine.

                  Thanks again for all the help.

                  -- Mike

                  6,675585
                  Grand MasterGrand Master
                  6,675585

                    Mar 15, 2010#9

                    Mike wrote:Would you please submit the problem to IDM? With your past experience, they'll probably accept your report with more authority than mine.
                    I reported it. But my bug reports are not processed with a higher priority than reports from others. For some small problems I reported I'm waiting already years to be fixed. As long as not enough other users are reporting the same problem, I must wait for a fix, too.

                      Apr 13, 2010#10

                      The problem with executing a script twice on all opened files when running it from command line without using ,e and without closing all opened files from within the script was fixed with UE v16.00.0.1036.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      5
                      NewbieNewbie
                      5

                        Apr 13, 2010#11

                        Thanks for the notification.

                        I've just upgraded to version 16 and registered my copy.

                        -- Mike