protected ProcessOutput invokeScript ( String script ) { File file = null ; try { //create temporary file file = File . createTempFile ( "fax4j_" , ".vbs" ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to create temporary vbscript file." , exception ) ; } file . deleteOnExit ( ) ; //generate command string StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( this . getVBSExePath ( ) ) ; buffer . append ( " \"" ) ; buffer . append ( file . getAbsolutePath ( ) ) ; buffer . append ( "\"" ) ; String command = buffer . toString ( ) ; try { //write script to file IOHelper . writeTextFile ( script , file ) ; } catch ( IOException exception ) { throw new FaxException ( "Unable to write vbscript to temporary file." , exception ) ; } //get logger Logger logger = this . getLogger ( ) ; logger . logDebug ( new Object [ ] { "Invoking command: " , command , " script:" , Logger . SYSTEM_EOL , script } , null ) ; //execute command ProcessOutput vbsOutput = ProcessExecutorHelper . executeProcess ( this , command ) ; //get exit code int exitCode = vbsOutput . getExitCode ( ) ; //delete temp file boolean fileDeleted = file . delete ( ) ; logger . logDebug ( new Object [ ] { "Temp script file deleted: " , String . valueOf ( fileDeleted ) } , null ) ; if ( exitCode != 0 ) { throw new FaxException ( "Error while invoking script, exit code: " + exitCode + " script output:\n" + vbsOutput . getOutputText ( ) + "\nScript error:\n" + vbsOutput . getErrorText ( ) ) ; } return vbsOutput ; }
Invokes the VB script and returns the output .