Safety-certified tools Tools for Automotive Applications C-STAT Static analysis C-RUN Runtime analysis Debugging and trace probes IAR Visual State
This Technical Note discusses the use of pre- and post-build actions.
When specifying pre-build and post-build action command lines:
Using IAR Embedded Workbench for Arm as an example, any of the following commands can be used to display the version of ielfdumparm.exe in the build log window:
Figure 1 ielfdumparm --version
To use shell-internal commands, such as DIR, ECHO, PATH, or REM, a shell must be started. See the screenshot below for an example.
Figure 2 - CMD.EXE /C DIR "$PROJ_DIR$\*.c"
Using the shell, it is possible to redirect output from shell commands and executables to a file. The following examples use a fictitious Windows executable named app.exe.
Example I/O 1: Interactively at a Windows command prompt:
app.exe > output.txt 2>&1
Example I/O 2: From a build action command line:
CMD /C "app.exe > $PROJ_DIR$\output.txt 2>&1"
Example I/O 3: The same applies when only one "CMD /C" leaves the output file empty:
CMD /C "CMD /C "app.exe > $PROJ_DIR$\output.txt 2>&1""
Using a .cmd file, you get a detachable command shell automatically. Therefore, you need one less "CMD /C" compared with a plain build action command line.
For example, with a file build.cmd located in the project directory, an alternative to Example I/O 3 could be a build action like
And a file build.cmd containing
PATH > %1\output.txt 2>&1
In IAR Embedded Workbench for Arm 8.20.2 (and later), a detachable command shell (.cmd) cannot be used, however, a detachable process can be used, and from that process the .cmd can be invoked. The only drawback is that the I/O input back to IAR Embedded Workbench cannot be used.
A detachable process can be created from a Visual basic script (file extension .vbs).
The redir.vbs file looks like:
Set runner = CreateObject("WScript.Shell")
args = WScript.Arguments(0)
Call runner.Run(args, 1, true)
The the_doer.cmd file looks like:
Echo "I am doing something"
Figure 3 – ' Wscript $PROJ_DIR$\redir.vbs "cmd /c $PROJ_DIR$\the_doer.cmd" '
Some example files are available via this link. Note that these project files (.ewp) require IAR Embedded Workbench for Arm 7.80 or later.
The example files for the detachable process are available via this link. Note that is in IAR Embedded Workbench for Arm 8.20.2 or later that detachable process can be used.
This Technical Note discusses the use of pre-build and post-build actions as available in IAR Embedded Workbench.
While based on practical use of Microsoft products and documentation, these comments and suggestions are to be viewed as guidelines and inspiration.
All product names are trademarks or registered trademarks of their respective owners.