Yes I found the same as you. It seems that the behaviour of callSystem is to always look for a program with that name, whereas what you are probably wanting to execute is a 'DOS' style command.
I came up against this myself when automatically exporting frames of an animation using the BMP output module and wanting to strip the zeroes off the end e.g. where the standard output module gives frame.bmp00023
The solution is to run the command prompt itself, giving it the '/c' argument which lets you run a command as the next argument. Like so:
var myCommand = "echo Hello"
system.callSystem("cmd /c \""+myCommand+"\"");
Now, all those slashes and quotes look a bit tricky, I agree, but here's whats going on.... If you just wrote this:
system.callSystem("cmd /c "+myCommand);
The system would think that your 'command' was only the word 'echo' since there is a space after it, and spaces separate parameters, don't they?
What you need to do is put your command (our variable myCommand) into quotes, as cmd sees it, thus making it one command string. For clarity, the system must see this:
cmd /c "echo Hello"
Of course, this isn't as simple as just writing the quotes into our JavaScript line because it would confuse the JavaScript interpreter into thinking we're ending our callSystem command. So to insert a quote into the command string and have it remain invisible to JavaScripts interpreter we put an escape character '\' before it.
A limitation of this approach is that only one line can be executed at once. If you needed to execute many commands, especially where they depend on each other, it would be better to have your code write out a batch file which it then calls with this method.
I hope this is clear, good luck, and let me know if what you're trying to do still isn't working.
Ah! that did it.. Thanks for that Chris.. It's hard to figure these things out when you are on a mac and can't try things out.. If only the manual made mention that mac and windows work differently with systemCall... ahh.. one can only dream...
Anyway, there is one more thing to point out. DOS returns a Carriage return and a line feed when you poll it.. so if you are capturing the output for use in something else.. you'll probably want to remove the CR/LF as so:
This thread has been very helpful. I'm getting closer to getting this to work but I'm getting stuck still. Below is my test code. I'm trying to run a script in Photoshop from After Effects. The code below successfully launches Photoshop but doesn't pop up the alert that's in the "target.jsx" script. After Effects is waiting for Photoshop to finish and is frozen until I close Photoshop. The command that I'm building with the strings correctly runs the script from a dos prompt. Any idea why it's not working?
byronnash wrote:This thread has been very helpful. I'm getting closer to getting this to work but I'm getting stuck still. Below is my test code. I'm trying to run a script in Photoshop from After Effects. The code below successfully launches Photoshop but doesn't pop up the alert that's in the "target.jsx" script. After Effects is waiting for Photoshop to finish and is frozen until I close Photoshop. The command that I'm building with the strings correctly runs the script from a dos prompt. Any idea why it's not working?
#target "AfterEffects"
var runString = '"C:\\Adobe\\Adobe Photoshop CS2\\Photoshop.exe"';
var sString = ' "C:\\Documents and Settings\Byron\\Desktop\\target.jsx"';
system.callSystem("cmd /c ""+runString+sString+""");
alert(runString+sString);
Have you tried putting the script in PS' scripts folder? Maybe it cannot resolve the path properly. You can also try routing the execution thru Bridge. Bridge by itself can open and close PS... Might be worth considering.
Hey Byron,
you've probably already figured it out
but in case you're still encountering problems, you may try that (adjust to your path):
- first script (launched from AE): "script_1.jsx"
if (system.osName.indexOf("Windows") != -1){//this is where the pc running stuff goes
var runString = '"C:\\Adobe\\Adobe Photoshop CS2\\Photoshop.exe"';
var sString = theFile.absoluteURI.replace(/\//g, "\\");//change the forward slashes to backslashes
sString = sString.replace(/\\c\\/,'"C:\\');//correct the drive letter, assuming it is on the C drive
sString = sString.replace(/%20/g," ");//change the %20 to spaces
sString += '"';
//alert(runString+" "+sString);
var runit = system.callSystem("cmd /c \""+runString+" " +sString+"\"");
if(runit){alert("we ran the PS script")};
}
The problem I'm having now is trying to get AE to wait on the PS script to finish before executing the rest of the script. Is that even possible? I tried putting the callSystem into a variable but it doesn't seem to be working. Ideas?