質問

I'm writing a script for Illustrator CS6 in ExtendScript. At the end of my script, I want to spawn a task (a second script, in Ruby) using File.execute(). However, it's not working. And I'm at a loss as how to debug the problem -- how can I figure out why this isn't working?

Here's the end of my ExtendScript file:

// Do a bunch of other work, then:
var rubyFile = new File(scriptFolder + 'BuildHtmlWalkthrough.rb');
alert(rubyFile.exists);
var result = rubyFile.execute(); 
alert(result);

Both rubyFile.exists and result are always true, indicating that the script launched OK. But the script does not appear to run, at all. I've tried the following diagnostics:

  • The Ruby script does successfully run from the command line. The script's permissions are -rwxr-xr-x
  • I added a call to system("touch /blah/blah/blah") as the very first line of the Ruby script. The file does not get touched.
  • I thought maybe the ExtendScript process was terminating before the Ruby script could run, so I added a long for loop after rubyFile.execute(). Spinning for > 30 seconds did not help.

What can I do to debug, or solve, this problem?

I'm on MacOS X v10.9.1. And for reference, this is the documentation for File.execute():

File.execute (): Boolean

Core JavaScript Classes

Executes or opens this file using the appropriate application, as if it had been double-clicked in a file browser. You can use this method to run scripts, launch applications, and so on. Returns true immediately if the application launch was successful.

役に立ちましたか?

解決

It's probably doing the "opens this file using the appropriate application" instead of executing, and returns true because the file successfully opens (or is already open in its associated app). If I have a python script and do

f= new File("~/Documents/misc_scripts/getpixelrgb.py");
f.execute();

, it opens it in my script editor, even if the file's execute flags are set.

I'm on OSX, btw

In After Effects, there is system.callSystem() to execute command line commands, but I'm afraid that is absent in Illustrator (I'm assuming you're doing this for Illustrator because of the tag). Are you on OSX or Windows? There are ways around this, by making an executable .app (OSX) or .exe (Win) and calling that with execute(). If I were doing this, I'm on OSX and I'd make an AppleScript app that does 'do shell script' to make the ruby system call. On Windows, it's different. One solution you might like if you're on windows: ocra, which is ruby-specific (http://ocra.rubyforge.org/). It may be possible to run a .bat file on Windows that calls the ruby script, but I'm not sure.

[edit!]

Terribly sorry for the extraneous Windows info (for someone else, I guess). Just saw your note about being on OSX. So you might want to use the AppleScript solution.

[edit again]

So, if my ruby script ("test.rb") is:

#!/usr/bin/env ruby
print "Hello"

and my AppleScript is:

do shell script "cd /testing_folder/; ruby test.rb"

Then I get "Hello" returned in AppleScript, but ExtendScript will just return true.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top