Running an .exe from a Javascript

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

slehar

Running an .exe from a Javascript

Post by slehar »

Is it possible to run an executable file from a JavaScript?

I wrote a program in another language and would like to call its .exe file from within my JavaScript.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Paul MR

Running an .exe from a Javascript

Post by Paul MR »

Yes...
Code: Select allvar file = new File("c:/folder/fileNane.exe");
file.execute();

or if using CS4 you can use system();
slehar

Running an .exe from a Javascript

Post by slehar »

Never mind! I found it!

The system( ) call does it, just pass it a DOS command string, e.g.

system("DIR > DIRLIST.TXT");

does a directory listing and sends the output to a file.

Thanks anyways!
slehar

Running an .exe from a Javascript

Post by slehar »

Oops! Didn't notice there was already a reply posted -- with a different solution!

Thanks!
slehar

Running an .exe from a Javascript

Post by slehar »

But how to you pass it command-line arguments?

I've tried

var commandLine = 'prog.exe arg1 arg2 arg3'

and

var commandLine = 'prog.exe "arg1" "arg2" "arg3" '

and then

result = system(commandLine)

or

var file = new File(commandLine);
result = file.execute();

and "result" always comes out "false", the executable doesn't execute.
Mike Hale

Running an .exe from a Javascript

Post by Mike Hale »

slehar

Running an .exe from a Javascript

Post by slehar »

Wow! Thats a very thorough example! Thanks!

For my purposes I managed with something considerably simpler.

My program, CorrectBrightness.exe, takes 3 command line arguments which are Image.tif (input image for brightness correction), ImageCorrBrt.tif (output image with brightness corrected), and BrightnesFunc.dat (brightness correction data).

Code: Select all

var exeFile = "C:\\Users\\slehar\\Documents\\MATLAB\\CorrectBrightness.exe  ";
var inFile = "C:\\Users\\slehar\\Documents\\MATLAB\\Image.tif  ";
var outFile = "C:\\Users\\slehar\\Documents\\MATLAB\\ImageCorrBrt.tif  ";
var bfuncFile = "C:\\Users\\slehar\\Documents\\MATLAB\\BrightnessFunc.dat  ";

var batFile = new File( "C:\\Users\\slehar\\Documents\\MATLAB\\CorrectBrightness.bat");
batFile.open("w");
batFile.writeln(exeFile + inFile + outFile + bfuncFile);
batFile.close();
batFile.execute();



This works! Thanks for your help!
m17

Running an .exe from a Javascript

Post by m17 »

I want ask where can I find hidden command like "system()",

"C:\Program Files\Adobe\Adobe Photoshop CS4\Scripting\Documents\Photoshop CS4 JavaScript Ref.pdf" has not tell that

BTW: Thanks, the code work fine