Highlighted

ExtendScript: run external command synchronously

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

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

Views

104

Likes

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

ExtendScript: run external command synchronously

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

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

Views

105

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 05, 2020 0
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

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!

Likes

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
Reply
Loading...
Oct 05, 2020 0
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 05, 2020 0
Adobe Employee ,
Oct 05, 2020

Copy link to clipboard

Copied

Interesting...

 

What is actually being _done_, by that executing script?

Likes

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
Reply
Loading...
Oct 05, 2020 0
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Oct 05, 2020 0
Explorer ,
Oct 06, 2020

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Oct 06, 2020 0
Adobe Employee ,
Oct 06, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 06, 2020 0
Explorer ,
Oct 06, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 06, 2020 0
Adobe Employee ,
Oct 06, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 06, 2020 0