• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

file.execute() not working for bat file

Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 25, 2015 Feb 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.

Votes

Translate

Translate
Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2015 Feb 25, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

LATEST

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....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines