To resolve this issue I used MSWindows.WinExec() and AdminService.Sleep() functions.
Example:
Let’s assume that we need to run dotNetApp.exe application. The command is "dotNetApp.exe dotNetApp.ini". I’m creating the batch file:
dotNetApp.exe dotNetApp.ini copy dotNetApp.ini done.txt
The second step is required as a "Process Completed" indicator.
//==============================================================
// setup sleep interval (1 sec) and timeout (1 min) #define SLEEP_INTERVAL 1000 #define MAX_SLEEP_ITERATIONS 60
String exeFile = 'c:\temp\dotNetApp.exe' String iniFile = 'c:\temp\dotNetApp.ini'
// create temporary folder Integer timeTick = Date.Tick() String processDir = Str.Format( 'c:\temp\TEMP_%1\', timeTick ) File.Create( processDir )
// dummy file. "Process Completed" indicator String doneFile = processDir + 'done.txt'
// batch file to run "dotNetApp.exe dotNetApp.ini" and create done.txt as a "Process Completed" indicator String batchFile = processDir + 'dotNetApp.bat'
CreateBatchFile( batchFile, exeFile, iniFile, doneFile ) Execute( error, batchFullPath, doneFullPath )
File.Delete( doneFile ) File.Delete( batchFile ) File.Delete( processDir )
/* ... some OScript code ... */
function void Execute( String batchFile, String doneFile ) Dynamic result = MSWindows.WinExec( batchFile )
Boolean fileFound = False Integer i for i = 1 to MAX_SLEEP_ITERATIONS if File.Exists( doneFile ) fileFound = True break end AdminService.Sleep( SLEEP_INTERVAL ) end
if ! fileFound // generate TIMEOUT ERROR here end end
function void CreateBatchFile( String batchFileName, String exeFile, String iniFile, String doneFile ) String cmd File.Create( batchFileName ) File batchFile = File.Open( batchFileName, File.WriteMode )
cmd = Str.Format( '"%1" "%2"', exeFile, iniFile ) File.Write( batchFile, cmd )
cmd = Str.Format( 'copy "%1" "%2"', iniFile, doneFile ) File.Write( batchFile, cmd ) // create dummy file to be sure the process is completed
File.Close( batchFile ) end
Sergiy Bagriy Technical Manager
Xybion Corporation, 3331 Street Rd, Suite 300 Bensalem, PA, 19020, USA
sergiy.bagriy@gmail.com
I don't know if it's clear. It certainly requires more development effort, but leads to a stronger app.
Pierre