'------------------------------------------------------------------------------ FUNCTION Execute (Program AS STRING, Arguments AS STRING, nShow AS LONG) AS DWORD ' Advanced Shell. Example of how to use : ' Local PID As Dword ' PID = Execute( Environ$("COMSPEC"), "/C dir " & $Dq & folderName & $Dq & " /ad /s /b > tmp.txt", 0 ) ' WaitForSingleObject PID, %INFINITE ' activate this line if you want synchronous shell ' CloseHandle PID LOCAL ShellInfo AS SHELLEXECUTEINFO ShellInfo.cbSize = SIZEOF(ShellInfo) ShellInfo.fMask = %SEE_MASK_FLAG_NO_UI OR %SEE_MASK_NOCLOSEPROCESS ShellInfo.lpFile = STRPTR(Program) ShellInfo.lpParameters = STRPTR(Arguments) ShellInfo.nShow = nShow IF ShellExecuteEx(ShellInfo) THEN FUNCTION = ShellInfo.hProcess END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ SUB WaitForThread(BYREF TID AS DWORD) ' deadline in second LOCAL lRes AS LONG DO ' Wait for the thread to finish DIALOG DOEVENTS SLEEP 0 lRes = WaitForSingleObject(TID, 100) LOOP UNTIL lRes <> %WAIT_TIMEOUT KillThread TID END SUB '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ SUB KillThread(BYREF TID AS DWORD) LOCAL lRes AS LONG THREAD SUSPEND TID TO lRes CloseHandle TID THREAD CLOSE TID TO lRes TID = 0 END SUB '------------------------------------------------------------------------------ '-------------------------------------------------------------------------------- FUNCTION RUN_CMD(BYVAL cmdLine AS STRING, OPTIONAL BYVAL folder AS STRING) AS LONG LOCAL rep AS STRING LOCAL ff AS LONG LOCAL PID AS DWORD IF folder <> "" THEN rep = folder ELSE rep = ENVIRON$("TEMP") + "\" rep = RTRIM$(rep, "\") + "\" ff = FREEFILE OPEN rep + "temp.bat" FOR OUTPUT AS #ff PRINT #ff, "@echo off" PRINT #ff, LEFT$(rep, 2) PRINT #ff, "cd " + $DQ + rep + $DQ PRINT #ff, cmdLine CLOSE PID = Execute(rep + "temp.bat", "", 0) WaitForThread PID ' Wait for the script to finish KILL rep + "temp.bat" END FUNCTION '-------------------------------------------------------------------------------- '-------------------------------------------------------------------------------- FUNCTION DUMP_CMD(BYVAL cmdLine AS STRING, OPTIONAL BYVAL folder AS STRING) AS STRING LOCAL rep, e AS STRING LOCAL ff AS LONG LOCAL PID AS DWORD IF folder <> "" THEN rep = folder ELSE rep = ENVIRON$("TEMP") + "\" rep = RTRIM$(rep, "\") + "\" ff = FREEFILE OPEN rep + "temp.bat" FOR OUTPUT AS #ff PRINT #ff, "@echo off" PRINT #ff, LEFT$(rep, 2) PRINT #ff, "cd " + $DQ + rep + $DQ PRINT #ff, cmdLine + " > dump.txt 2>&1" CLOSE PID = Execute(rep + "temp.bat", "", 0) WaitForThread PID ' Wait for the script to finish KILL rep + "temp.bat" ff = FREEFILE OPEN rep + "dump.txt" FOR BINARY AS #ff GET$ #ff, LOF(#ff), e CLOSE KILL rep + "dump.txt" FUNCTION = RTRIM$(e, ANY $CRLF) END FUNCTION '--------------------------------------------------------------------------------