1

I have a nodejs code, that exec an extendscript code, and i need to get a result from the extendscript if the code result is true or false(like return or something else).

The only way that I found is to create a flag-file when the extendscript finished, and then to check it in the node.

Is there a better way doing this?

Thank you all!

Ziki
  • 1,390
  • 1
  • 13
  • 34

2 Answers2

0

I'm assuming that you can edit extendscript since you have mentioned 'you can create flag-file'.

In your extendscript instead of creating flag-file write the boolean value in standard output.

In your parent script (which is actually calling the extendsscript) use something like

var cp = exec('extendsscript');
cp.stdout.on('data', function(data) {
    // do whatever you want to do with the data. Might have to change encoding
});

Line of advice, if you are planning to get small amount of data (status message) exec is fine but for large amount of data use spawn instead as exec buffers data in memory.

years_of_no_light
  • 938
  • 1
  • 10
  • 24
  • Thanks, but how can I send from the extendscript to the stdout? (return true not works..) – Ziki May 22 '15 at 12:04
  • What kind of file is extendsscript? – years_of_no_light May 23 '15 at 05:53
  • it's javascript code but for adobe application such after effects, photoshop etc. – Ziki May 24 '15 at 20:08
  • So assuming that you are calling it as `exec('node extendsscript.js')`, you can do `process.stdout.write(status)`. Be careful about the truthy and falsy value as you are getting the data as string. – years_of_no_light May 25 '15 at 06:53
  • Is it possible for you to put some dummy code? Your file should be an node file (as you mentioned 'it's javascript code but for adobe..') and you are calling it from node exec. process should be available by default. You can find the total scenario [here](http://krasimirtsonev.com/blog/article/Nodejs-managing-child-processes-starting-stopping-exec-spawn) – years_of_no_light May 25 '15 at 09:42
  • It's a javascript based ecmascript 3, and i don't running the javascript code. i'm running after effects with arguments that runs an extendscript file.. like: exec(' "C:Program Files/Adobe/Adobe After Effects CS6/Support Files/AfterFX.exe" -r "path/to/extendscript/file.js" '); – Ziki May 25 '15 at 10:52
  • If thats the case how you were creating flag-file file? – years_of_no_light May 25 '15 at 19:53
  • In the extendscript, before the code finishing the execution, I crate a file names: true or false. then the node knows when the exec finished, and then i search for the file.. – Ziki May 26 '15 at 06:47
  • Is http://blogs.adobe.com/aftereffects/files/2012/06/After-Effects-CS6-Scripting-Guide.pdf your API? – years_of_no_light May 26 '15 at 07:11
  • Yes, and also this: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf – Ziki May 26 '15 at 07:40
  • Looks like you have access to standard javascript console. Try writing `console.log(boolStat)` in extendscript. and `cp.stdout.on('data',function(status) { // });` – years_of_no_light May 26 '15 at 07:57
  • I tryed this without success... var b = require('child_process').exec('"C:/Program Files/Adobe/Adobe After Effects CS6/Support Files/AfterFX.exe" -s "$.write(\"true\")"'); b.stdout.on('data', function(data){console.log('hi' + data);});... $.write is the only option to write to the console.. but there is not console.log(). – Ziki May 26 '15 at 09:23
  • [This](http://stackoverflow.com/questions/8545497/console-log-with-photoshop-scripting-extendedscript-toolkit) might be useful for you. I think you have to write the `$.write` inside the script. – years_of_no_light May 26 '15 at 09:52
0

If you install extendscript-stream you can add $.write(JSON.stringify(data)); to your ExtendScript file to pipe data back to Node.js.

Bruno
  • 898
  • 14
  • 17