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.
Running an .exe from a Javascript
Running an .exe from a Javascript
Yes...
Code: Select allvar file = new File("c:/folder/fileNane.exe");
file.execute();
or if using CS4 you can use system();
Code: Select allvar file = new File("c:/folder/fileNane.exe");
file.execute();
or if using CS4 you can use system();
Running an .exe from a Javascript
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!
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!
Running an .exe from a Javascript
Oops! Didn't notice there was already a reply posted -- with a different solution!
Thanks!
Thanks!
Running an .exe from a Javascript
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.
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.
Running an .exe from a Javascript
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!
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!
Running an .exe from a Javascript
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
"C:\Program Files\Adobe\Adobe Photoshop CS4\Scripting\Documents\Photoshop CS4 JavaScript Ref.pdf" has not tell that
BTW: Thanks, the code work fine