Coming a bit late to the game.
Original Message:
Sent: 09-22-2025 20:59
From: Nick Lawrence
Subject: Wait until Run Program has finished
Compilation Successful
Thanks!
Now I have to build the rest of my code around this
------------------------------
Nick Lawrence
Senior Spatial Science Officer
Department of Transport and Main Roads (QLD)
Brisbane QLD
Original Message:
Sent: 09-17-2025 04:23
From: Warren Vick
Subject: Wait until Run Program has finished
Hello Nick,
It looks like this platform has added some special characters to the end of the CREATE_NO_WINDOW definition, which appears as underscores when copy/pasted.
define CREATE_NO_WINDOW &H8000000___
Simply take those underscores off and you should be fine. I tested the code snippet and it compiles without error. Good luck!
Regards,
Warren Vick
------------------------------
Warren Vick
Europa Technologies Ltd.
Original Message:
Sent: 09-16-2025 19:40
From: Nick Lawrence
Subject: Wait until Run Program has finished
Sorry, it did not compile
For line 53 rc = CreateProcessA(0, cmdLine, 0, 0, 0, NORMAL_PRIORITY_CLASS+CREATE_NO_WINDOW, 0, 0, si, pi)
The error is Found [___] while searching for [)].
------------------------------
Nick Lawrence
Senior Spatial Science Officer
Department of Transport and Main Roads (QLD)
Brisbane QLD
Original Message:
Sent: 09-09-2025 02:54
From: Nick Lawrence
Subject: Wait until Run Program has finished
Thanks! I will try this out
------------------------------
Nick Lawrence
Senior Spatial Science Officer
Department of Transport and Main Roads (QLD)
Brisbane QLD
Original Message:
Sent: 09-09-2025 02:51
From: Warren Vick
Subject: Wait until Run Program has finished
Hello Nick,
Below is some stock MapBasic code that I've been using for many years and it still seems to work well.
There are a few data structures, definitions and Windows functions to prototype, but these are all in support of the local function ExecuteAndWait(). You simply pass in your command line... RoboCopy plus parameters in your case. The function returns zero if successful.
This version will run the command silently, but if you want to see a Command Prompt window appear so you can see what RoboCopy is doing, simply remove the +CREATE_NO_WINDOW from the call to CreateProcessA. Note, however, if you're doing lots of these, it snatches Window focus each time, which makes using your PC difficult!
Hope it's helpful.
Regards,
Warren Vick
Europa Technologies Ltd.
Type STARTUPINFO cb As Integer lpReserved As String lpDesktop As String lpTitle As String dwX As Integer dwY As Integer dwXSize As Integer dwYSize As Integer dwXCountChars As Integer dwYCountChars As Integer dwFillAttribute As Integer dwFlags As Integer wShowWindow As Smallint cbReserved2 As Smallint lpReserved2 As Integer hStdInput As Integer hStdOutput As Integer hStdError As IntegerEnd TypeType PROCESS_INFORMATION hProcess As Integer hThread As Integer dwProcessID As Integer dwThreadID As IntegerEnd Typedefine NORMAL_PRIORITY_CLASS &H20define CREATE_NO_WINDOW &H8000000 define INFINITE -1declare function CreateProcessA Lib "kernel32"(ByVal lpApplicationName As Integer, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Integer, ByVal lpThreadAttributes As Integer, ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As Integer, ByVal lpCurrentDirectory As Integer, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Integerdeclare function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer,ByVal dwMilliseconds As Integer) As Integerdeclare function GetExitCodeProcess Lib "kernel32" (byval hProcess As Integer, lpExitCode As Integer) as Integerdeclare function CloseHandle Lib "kernel32" (hObject As Integer) As smallintdeclare function ExecuteAndWait(ByVal cmdLine as string) as integerfunction ExecuteAndWait(ByVal cmdLine as string) as integer dim exitCode as integer dim rc as integer dim pi as PROCESS_INFORMATION dim si as STARTUPINFO si.cb = 256 si.dwFlags = 1 si.wShowWindow = 1 rc = CreateProcessA(0, cmdLine, 0, 0, 0, NORMAL_PRIORITY_CLASS+CREATE_NO_WINDOW, 0, 0, si, pi) rc = WaitForSingleObject(pi.hProcess, INFINITE) rc = GetExitCodeProcess(pi.hProcess, exitCode) rc = CloseHandle(pi.hProcess) rc = CloseHandle(pi.hThread) ExecuteAndWait = exitCodeend function
------------------------------
Warren Vick
Europa Technologies Ltd.
Original Message:
Sent: 09-09-2025 02:00
From: Nick Lawrence
Subject: Wait until Run Program has finished
I want to write a mbx that executes a RoboCopy command to copy specific MapInfo tables to the user's C: drive, for fast access.
I want to use RoboCopy because it will only run if the source files are different to the destination files. This saves unnecessary work.
Is there a way to make the mbx wait until the RoboCopy command has finished running before proceeding with the next part of the mbx script?
The Help file for Run Program indicates that the mbx will continue whilst the spawned task (RoboCopy) is still running
------------------------------
Nick Lawrence
Senior Spatial Science Officer
Department of Transport and Main Roads (QLD)
Brisbane QLD
------------------------------