Home › Forums › General XMetaL Discussion › Run batch file from macro › Reply To: Run batch file from macro
Reply to: Run batch file from macro
November 5, 2010 at 11:52 pmI think you may need to pass an 8.3 file path to WScript.Shell to do what you want. FSO exposes a property that lets you get the 8.3 path that is called “ShortPath”.
Here's an example that should work (I've removed all the space and JScript backslash munging for clarity and just hardcoded double backslashes as per JScript string requirements).
//JScript:
function shortPath(path) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shortPath = fso.GetFile(path).ShortPath;
fso = null;
return (shortPath);
}
var runCmd = shortPath("C:\folder name with spaces\myfile.bat");
Application.Alert(runCmd);
var wsShell = new ActiveXObject("WScript.Shell");
wsShell.Run(runCmd);
wsShell = null;
And here's the content of myfile.bat that I'm testing with:
rem this is a test
pause