问题
Summary:
Is there a way to use the execute() function to pass a parameter to a Python script, and have the Python script use the parameter in its execution, then return the result to ExtendScript?
Context: I'm building a script for Illustrator that has to query a web service, process the resultant XML file, and return the results to the user. This would be easy if I were using one of the applications that support the Socket feature, but Illustrator doesn't. My next thought, was that I can achieve the HTTP request and XML parsing in Python. I'm at a loss on how to bridge the two.
回答1:
Option 1 (BridgeTalk)
I had to do something like this to run an external PNG processor from both Photoshop and Illustrator. Neither of those applications have the ability to execute external programs from ExtendScript. (See Option 2.) Adobe Bridge's app
object has a system
method that executes a command in the system shell. Using a BridgeTalk
object, you can call that method remotely from Illustrator. You'll only get the exit code in return, though. So you'll need to redirect your program's output to a file and then read that file in your script.
Here's an example of using BridgeTalk
and Adobe Bridge to run an external program:
var bt = new BridgeTalk();
bt.target = 'bridge';
bt.body = 'app.system("ping -c 1 google.com")';
bt.onResult = function (result) {
$.writeln(result.body);
};
bt.send();
Pros
- Asynchronous
- Can easily retrieve the exit code
- Can use shell syntax and pass arguments to the program directly
Cons
- Adobe Bridge must be installed
- Adobe Bridge must be running (although BridgeTalk will launch it for you, if needed)
Option 2 (File.prototype.execute)
I discovered this later and can't believe I missed it. The File
class has an execute
instance method that opens or executes the file. It might work for your purposes, although I haven't tried it myself.
Pros
- Asynchronous
- Built into each ExtendScript environment (no inter-process communication)
Cons
- Can't retrieve the exit code
- Can't use shell syntax or pass arguments to the program directly
回答2:
Extendscript does support Socket, following is the code snippet
reply = "";
conn = new Socket;
// access Adobe’s home page
if (conn.open ("www.adobe.com:80")) {
// send a HTTP GET request
conn.write ("GET /index.html HTTP/1.0\n\n");
// and read the server’s reply
reply = conn.read(999999);
conn.close();
}
来源:https://stackoverflow.com/questions/18969372/execute-external-script-in-extendscript-for-illustrator