Using minim.exe from batch files.
Some integration tasks require use MiniM Database Server from batch files (.bat and .cmd). This article describe some possibilities how to call minim.exe from batch environment and exchange data.
Further examples assumes that the server is installed in the directory w:\minim and that execution of command files produced on the server.
Call MiniM process with output to screen or to file
MiniM process provides option -std to use standard input-output channels (stdin-stdout) and option -h to halt process after end of commands. To indicate that it is necessary to process commands provided option -x. Example:
file 01.bat: @echo off set minim=w:\minim\bin\minim.exe %minim% -std -h -x "w $zd($h),!"While this batch file executes, on the screen is displayed current date.
The same result we can write to file by using redirection:
%minim% -std -h -x "w $zd($h),!" > report.txtHere process's output is written to the file report.txt.
How to send several lines of commands from file
To send to MiniM process several lines of commands we can use text file with MUMPS commands. To tell to use file instead command argument, option -x provides special symbol @ (use file's content). For example, let the file 02.m contains MUMPS commands:
file 02.m: w "Now: ",$zd($h),! w "Version: ",$zv,!Then to call MiniM process we use symbol @:
file 02.bat: @echo off set minim=w:\minim\bin\minim.exe %minim% -std -h -x @02.mWhile this batch file executes current date and version is written to screen.
Send commands using redirection
To send commands to MiniM process we can use standatd input channel using option -std and redirection symbols | è <.
file 03.bat: @echo off set minim=w:\minim\bin\minim.exe echo w $zd($h),! | %minim%Here MiniM process reads line-by-line from standard input channel (stdin) and executes as MUMPS command sequence. MiniM process can automatically determine that one is running with input redirection and use options -std and -h by default even ones are not specified.
Pass parameters using batch files preprocessor
While MiniM process does not get parameters from batch file, process can operate only database state. To use parameters from batch file we should pass ones to MiniM process. One of possibility to transfer data is batch file preprocessor, which can expand special symbols %%. This is parameter sybstitution. For example, we can create command to execute by MiniM process:
file 04.bat: @echo off set minim=w:\minim\bin\minim.exe set a=123 %minim% -std -h -x "w \"Variable a is %a%\",!"While this batch file executes, message is printed to the screen:
Variable a is 123To use parameter substitution programmer should use right syntax decoration to make correct MUMPS command. Double quote (") need to be doubled.
Pass parameters using environment variables
Second possibility to pass parameters to MiniM process are environment variables. Batch file can assign environment variable and ones are accessible by MiniM process using group of functions $v("proc"). Example:
file 05.bat: @echo off set minim=w:\minim\bin\minim.exe set a=123 %minim% -std -h -x "w $v(\"proc\",9,\"a\")_456,!"Here batch file assign environment variable a and call MiniM process. MiniM process use function $v("proc",9) to read environment variable content and concatenate with string 456. Next common message is printed to the screen:
Accepting parameters from MiniM process using temporary batch file and environment variables
Batch file can accept parameters from MiniM process using child batch file creation. This temporary batch file can contain command sequence to assign environment variables in batch file notation. After creation one parent batch file can call temporary batch file and accept environment variable's changes. Example:
file 06.bat: @echo off set minim=w:\minim\bin\minim.exe set a=123 echo First value is %a% %minim% -std -h -x "w \"set a=\"_$v(\"proc\",9,\"a\")_456" > second.bat call second.bat del second.bat echo Second value is %a%Here batch file assign environment variable a and call MiniM process. MiniM process read environment variable content and make some operation (concatenation in this example). Common result are written to temporary batch file using output redirection (file second.bat). Parent batch file call this temporary file and accept environment varible changes. While this batch file executes to screen is written messages:
First value is 123 Second value is 123456
Download batfiles.zip (zip, 1.3Kb)Eugene Karataev
Emails: Info Tech Support