When working with different versions of a database structure between the developer and end user it can be necessary to make changes to the file names or file structure, external from 4D. This is generally necessary when a file that is open by the database needs to be renamed or deleted. On a Windows machine that can be done with a batch file that is run by 4D's LAUNCH EXTERNAL PROCESS command. The following code creates the batch file and runs it:
PLEASE NOTE: this batch file deletes the structure file of the current database!!!
$CRLF:=Char(Carriage return )+Char(Line feed )
$content:="ping -n 11 127.0.0.1 >NUL"+$CRLF
SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
$command:="cmd.exe /Cstart \"Title\" \""+$path+"\""
LAUNCH EXTERNAL PROCESS($command)
Looking at the content sent to the dbupdater.bat document there are four functions written into the batch file:
- "ping -n 11 127.0.0.1 >NUL"
The ping command is used as a 10 second pause so that 4D can quit before the rest of the batch file runs.
- "del \""+Structure file+"\""
This function deletes the current database's structure file. This is why the pause must be in place. The QUIT 4D command called immediately after LAUNCH EXTERNAL PROCESS must have run and quit the 4D application before this works.
- "START \"Title\" /MAX \""+Application file+"\""
This function starts the 4D Application that was running the database before, so the user can choose the new database structure to open and reopen it.
This function exits out of the command line window that was opened by LAUNCH EXTERNAL PROCESS.
Another important thing to note in the batch file is that a carriage return and line feed must be called between each command line function to be run.
In this example the structure file is removed, but no replacement is provided. For a more robust example of a batch file used to upgrade 4D databases see the "upgclnt.bat" file in the "4D Extensions" folder of 4D Client on Windows. Additionally, a script file for Mac can be found in the "4D Extensions" folder of 4D Client on MacOS. These script files are used for the automatic client update feature.