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

ExtendScript: run external command synchronously

Explorer ,
Oct 05, 2020 Oct 05, 2020

Is there a way to synchronooously execute a file (i.e., new File(exePath).execute()), but sychronously await the result/with a callback? I don't really want to activate the whole Node.js thing for the child_process command, as I couldn't get it to work the few times I've tried

TOPICS
SDK
1.6K
Translate
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
Adobe Employee ,
Oct 05, 2020 Oct 05, 2020

What sort of external ExtendScript command are you hoping to run, synchronously?

Translate
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 ,
Oct 05, 2020 Oct 05, 2020

An executable file - I've got that working, but it saves its output to a file that I want it to read after it's finished.

At the moment, I'm using a while loop to test for the file's existence, sleep for 1000ms, then proceed on existence. This causes the script to lock up if the executed script is ended early (i.e., the process dies before file write).

Therefore it'd be much more preferable for it to wait synchronously until the executable has exited, then check for file existence instead.

Thanks for your prompt response!

Translate
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 ,
Oct 05, 2020 Oct 05, 2020

Just to clarify, it is the JSX file running the external executable file - currently run as `new File('some.exe').execute()`

Translate
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
Adobe Employee ,
Oct 05, 2020 Oct 05, 2020

Interesting...

 

What is actually being _done_, by that executing script?

Translate
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 ,
Oct 05, 2020 Oct 05, 2020

Unfortunately I can't disclose fully what's going on - it's AI for a prorietary plugin, which outputs a JSON file that's used by the rest of the script.

I've been emulating it by calling a batch script with a timeout of 3 seconds during testing, where I came up with that hackjob solution outlined above, if you'd like a way to reproduce:

``` test.bat

timeout 3

echo [ "test" ] > test.json

```

 

``` index.jsx

var batPath = 'test.bat';

var jsonPath = 'test.json';

var batFile = new File(batPath );

batFile.execute();

 

while (!File(jsonFile).exists) {

  $.sleep(1000);

}

 

var output = JSON.parse(jsonFile);

// Rest of script

```

 

But if you close the terminal window before the timeout finishes, you'll discover the issue! That while loop, I'm assuming keeps on running, freezing up the script after any more calls to $. So it'd obviously be better to run it synchronously and avoid that while loop, as I can just test for file existence once the external command ends. Is that possible?

Translate
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 ,
Oct 06, 2020 Oct 06, 2020

Just found out about `system.callSystem` but I can't seem to get that to work. Is that not something that works with Premiere Pro?

Translate
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
Adobe Employee ,
Oct 06, 2020 Oct 06, 2020

There is no such call in PPro's ExtendScript API, but you _can_ fire command lines from the JavaScript layer of your panel.

Translate
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 ,
Oct 06, 2020 Oct 06, 2020

That sounds promising! Do you have any example? And does that call run synchronously/using a callback?

Translate
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
Adobe Employee ,
Oct 06, 2020 Oct 06, 2020
LATEST

Example = See the CEP HTML Test Panel. 

https://github.com/Adobe-CEP/CEP-Resources/tree/master/CEP_10.x/Samples/CEP_HTML_Test_Extension-10.0

> And does that call run synchronously/using a callback?

No; it's just a normal command line. 


Screen Shot 2020-10-06 at 2.09.49 PM.png

Translate
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