You could debug that code yourself by stripping down the command line and testing it part by part... starting with the CD command...
Doing this it shows two things:
- You get the error because you start your command line with an internal DOS command (the CD command). Apparently you can't use the Run method to run an internal DOS command since the Run method does not start a DOS interpreter on its own.
The reason normal programs work is because they are executables. An internal DOS command isn't an executable, but is actually part of the DOS interpreter.
This can be solved by starting the interpreter yourself like so:
cmd /c cd c:\blahblah
- Second, you forgot to enclose long path and file names with quotes:
cd "c:\Program Files\Messenger Plus!\etc"
So, your command line in the script should be:
jscript code:
var cmd = "cmd /c cd \"" + path + "\" & " +
"latex file.tex & " +
"dvipng -T tight -x 1200 -z 9 file.dvi";
And that will work...
However, for testing and debugging purposes you could temporarly do two things:
- change "cmd /c" to "cmd /k". This will keep the command window open and gives you the chance to actually see and check the output (more info on this if you type cmd /? in the interpreter). You must type "exit" to close the window and continue the script!
- change the second parameter of the Run method to 1, so the command window isn't hidden.
Thus for testing purposes, you could use:
jscript code:
var cmd = "cmd /k cd \"" + path + "\" & " +
"latex file.tex & " +
"dvipng -T tight -x 1200 -z 9 file.dvi";
var oShell = new ActiveXObject('WScript.Shell');
oShell.Run(cmd, 1, true);
oShell = null;
and when everything works ok, you change it to:
jscript code:
var cmd = "cmd /c cd \"" + path + "\" & " +
"latex file.tex & " +
"dvipng -T tight -x 1200 -z 9 file.dvi";
var oShell = new ActiveXObject('WScript.Shell');
oShell.Run(cmd, 0, true);
oShell = null;
PS: however, note that using the CD command to work around the dvipng limitation (you are absolutly sure you can't provide absolute paths in some way to dvipng, or set the input path to the script folder?) could cause a failure in case the script (and Plus!) wasn't installed on the default Windows drive.
The command "CD C:\blahblah" will not change the current drive to C. It will only change the path on the C-drive. So, if the current drive is D, the whole command line will fail again.
This is also easly solved by simply adding the command "C:" right before the "CD" command:
cmd /c C: & CD "c:\blahblah" & etc...
or:
jscript code:
var cmd = "cmd /c " + path.substring(0, 2) + " & cd \"" + path + "\" & " +
"latex file.tex & " +
"dvipng -T tight -x 1200 -z 9 file.dvi";
This also applies in the same way if you use batch files or whatever though!. So you see, in the end, and to come back to your question of "why?", if you want to make things bug proof, using an absolute path name and using the proper command line parameters is much easier and way more efficient and shorter than using batch files and trying to work around all sorts of stuff like external files. (Provided the tools do support the needed parameters of course. Otherwise you are forced to use a workaround. But in that case you still should use the most efficient workaround - which batch files are certainly not).