Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created December 1, 2009 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwlin/246475 to your computer and use it in GitHub Desktop.
Save pwlin/246475 to your computer and use it in GitHub Desktop.
Calling PHP CLI from ActiveX FSO and WScript.Shell
var php = {
cmd : function(command, nWindowType){
// Obtain a Temporary File Name
var oFS ;
var RunOutput = '' ;
oFS = new ActiveXObject("Scripting.FileSystemObject");
var cFile ;
cFile = oFS.GetSpecialFolder(2).Path+'\\'+ oFS.GetTempName() ;
// Execute the command and redirect the output to the file
var oShell ;
oShell = new ActiveXObject("WScript.Shell");
oShell.Run(command + " >" + cFile, nWindowType, true);
oShell = null ;
// Read output file and return
var oFile ;
oFile = oFS.OpenTextFile(cFile, 1, true) ;
RunOutput = oFile.ReadAll() ;
oFile.Close() ;
// Delete Temporary File
oFS.DeleteFile(cFile);
oFS = null ;
cFile = null ;
return RunOutput ;
}
}
// output = php.cmd('command /c php -v ', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment