Skip to main content
K.Daube
Community Expert
Community Expert
February 25, 2015
Answered

file.execute() not working for bat file

  • February 25, 2015
  • 2 replies
  • 2267 views

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");
  clipFile.open('w');
//  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.

This topic has been closed for replies.
Correct answer JoH

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:

  ....

  clipFile.writeln("pause");

  clipFile.close();

  clipFile.execute();

I'm using FM11 on Windows 7.

2 replies

JoHCorrect answer
Inspiring
February 25, 2015

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:

  ....

  clipFile.writeln("pause");

  clipFile.close();

  clipFile.execute();

I'm using FM11 on Windows 7.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
February 25, 2015

JoH,

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.

Klaus Göbel
Legend
March 2, 2015

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

"pause"

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 > "")

                {

                alert("ERROR");

                 }

        MyFile.writeln(MyDosCommand);

        MyFile.writeln("pause");

        MyFile.close();

        MyFile.execute();

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
February 25, 2015

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?