5 Replies Latest reply on Mar 2, 2015 8:48 AM by K.Daube

    file.execute() not working for bat file

    K.Daube Level 1

      Dear all,
      The purpose of my function copyToWinClipboard (text) is to get a string directly into the Windows Clipboard. The purpose is to allow the user of my project just to paste into the open-dialog of the application EndNote. I’m not certain whether the FM clipboard (supported by the copy/cut/paste methods for Doc) really fills into the Windows Clipboard also.
      In the PhotoShop script forum I found the idea how to do this.

      #target framemaker
      // note the blank in the path
      copyToWinClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");
      function copyToWinClipboard (text) {
        var theCmd, clipFile = new File(Folder.temp + "\\ClipBoardW.bat");
      //  theCmd = "echo \"" + text + "\" | clip"; // this doesn’t help either
        theCmd = "echo " + text + " | clip";
        clipFile.writeln (theCmd);
        clipFile.close ();
        clipFile.execute ();

      Running this script provides a short flicker (the command prompt), but the clipboard does not contain the expected string. However, when double clicking on the generated I:\!_temp\ClipBoardW.bat the clipboard is filled correctly.
      IMHO the execute method does not work correctly for bat files. In another area of my project-script i run an exe file with this method correctly.

        • 1. Re: file.execute() not working for bat file
          K.Daube Level 1

          If nothing helps for my first 'solution', my idea how to do this with the copy method looks a little bit heavy to me:

          • create a textframe with a paragraph on the first masterpage (which always exist)
          • write the string into this paragraph
          • select it
          • use Copy to get the selection into the clipboard
          • delete the text frame

          Would this be the desirable approach?

          • 2. Re: file.execute() not working for bat file
            JoH Level 2

            Just wanted to report that the sample script in your first post does work on my computer.


            You mention the command window comes up shortly, which indicates that the .bat file is executed.

            Maybe the execution fails at another point?


            If you want to keep the command window open and check for messages, add the "pause" command to the batch file:






            I'm using FM11 on Windows 7.

            • 3. Re: file.execute() not working for bat file
              K.Daube Level 1


              It seems that my system (W7 x64, FM-12) is special also here...

              The Pause has no effect on the display of the command window, it just flickers and disappears - and the clip-buffer contains still the old stuff.

              I have checked: the execute() retruns true - hence no error from the script.

              • 4. Re: file.execute() not working for bat file
                Klaus Göbel Level 3

                Hi Klaus,


                sorry for my late response.


                execute definitely works witch batch-files


                Here's a "batch" - example you can test.


                There are two methods to prevent window from closing:


                "|more" - kind of pagebreak


                var oTemp = app.UserSettingsDir + "\\tmp";

                    var MyDosCommand = "ipconfig.exe /a|more";

                    var MyPath = new Folder (oTemp);


                    if (!oTemp.exists)


                        var MyPath = new Folder (oTemp);

                        var lFehler = MyPath.create();



                    oTemp = oTemp + "\\" +"nw.bat";

                    var MyFile = new File (oTemp);


                         MyFile.open ('w');

                           if (MyFile.error > "")








                • 5. Re: file.execute() not working for bat file
                  K.Daube Level 1

                  Klaus, I have now tested on my wife's PC (W7, X32) - everything works correctly there.

                  As mentioned before, my W7 X64 system has some quirks - and this may be just onther one. The most annoying is that in my working environment FM (10 ... newest) does not interact with the ESTK. Hence my script development takes the loop Editor - Add/Refresh in the Script catalogue - Run - look at the console log...Editor ...

                  For this "Copy to clipboard" problem I have found another solution which I also had reported in this forum.


                  Also with your recent sample script on my W7 x64 the command console just flickers (it does not execute the pause!). Maybe I have some very special settings....