Thursday, October 5, 2017

Write a Batch File & Make File in Notepad

When writing C++ programs, you often want to set up your command prompt for building by setting the path and drive letter of your project.  Use a batch file to do this.

To compile all your files & run your program, you will accomplish this via a make file.  The batch file can call the make file.

Batch File

Sample batch file:

@echo off
cls
set DRIVE_LETTER=%CD:~0,2%
set PATH=%DRIVE_LETTER%\TDM-GCC-64\bin;%DRIVE_LETTER%\TDM-GCC-64\wxWidgets-3.1.0\lib\gcc510TDM_x64_dll;c:\windows\system32;c:\"Program Files"\KDiff3
set PROJECT_PATH=.
mingw32-make DRIVE_LETTER="%DRIVE_LETTER%" CURRENT_DIR="%PROJECT_PATH%"


For a complete tutorial, visit https://www.tutorialspoint.com/batch_script/batch_script_files.htm


  • Save batch files as .bat or .cmd at the end of the file name
  • @echo off
    • By default, a batch file will display its command as it runs.  
    • The purpose of the echo off command is to turn off the display for the whole script, except for the echo off command itself. 
    • The @ in front makes the command apply to itself as well
  • cls
    • clear the screen
  • set DRIVE_LETTER=%CD:~0,2%
    • Variables can be initialized via the 'set' command
    • if the value needs to be numeric in nature then add /A after the word set
    • DRIVE_LETTER is the variable name
    • %CD:~0,2% is the value that DRIVE_LETTER is being set to
    • %CD% prints the current working directory of the batch file or command running it
    • %CD:~0,3% will grab the first three characters of the path
    • %CD:~0,2% will grab the first two characters of the path
  • set PATH=something
    • PATH is the variable name
    • something is the path.  The example above sets the environment variable to the g++ compiler as well as wxWidgets
  • set PROJECT_PATH=.
    • PROJECT_PATH is the variable name
    • . is the current directory
  • mingw32-make DRIVE_LETTER="%DRIVE_LETTER%" CURRENT_DIR="%PROJECT_PATH%
    • mingw32-make will call the makefile that is in the specified directory
    • same as mingw32-make C: .

Make File

Use a make file to compile all your files & run your program without having to manually type everything in every time (saves you time).

Sample makefile:

# I am a comment.
#You can make variables in make files.  AutomatedMakefile is a variable
AutomatedMakefile = am

#the variable CC will be the compiler to use
CC = g++

#CXXFLAGS are the options I will pass to the compiler
#-Wno-deprecated-declarations tell the compiler to NOT warn about uses of functions, variables, and types marked as deprecated
#-g option allows for debugging tools
CXXFLAGS = -Wno-deprecated-declarations -g -O0

#PROJECT_PATH variable is set to CURRENT_DIR (which is taken from batch file)
PROJECT_PATH = $(CURRENT_DIR)

#COMPILE contains g++ -Wno-deprecated-declarations -g -O0 
COMPILE = $(CC) $(CXXFLAGS) $(INC_DIRS) -c 
LINK = $(CC) $(CXXFLAGS) $(LIB_DIRS)

FILES =PlayerGuessDriver.o Keyboard.o Random.o String.o ReadFile.o
EXECUTABLE = PGD.exe

all: PGD

PGD: $(FILES)
$(LINK) $(FILES) $(LIBS) -o $(EXECUTABLE)

PlayerGuessDriver.o: Keyboard.o Random.o String.o ReadFile.o
$(COMPILE) PlayerGuessDriver.cpp

Keyboard.o:
$(COMPILE) Keyboard.cpp
Random.o:
$(COMPILE) Random.cpp
String.o:
$(COMPILE) String.cpp
ReadFile.o:
$(COMPILE) ReadFile.cpp

COMMON DOS (COMMAND PROMPT) COMMANDS


  • CD - change directory
  • CLS - clear the screen
  • COPY - copy files from one location to anotehr
  • DEL - deletes files (not directories)
  • DIR - list out the contents of a directory
  • DATE - get the system date
  • ECHO - display a message
  • EXIT - exit the command prompt
  • MD - create a new directory in the current location
  • MOVE - move files or directories between directories
  • PATH - displays or sets the path variable
  • PAUSE - prompts the user and waits for a line of input to be entered
  • RD - remove directory (must be empty first)
  • REN - rename file/directory
  • START - starts a program in new window, or opens a document
  • TIME - sets or displays the time
  • TYPE - prints the contents of a file or files to the output
  • CHOICE - provides a list of options to the user
  • CMD - invokes another instance of command prompt
  • IPCONFIG - displays Windows IP configuration (get your IP address)
  • PING - sends ICMP/IP "echo" packets over the network to the specified address
  • SHUTDOWN - shuts down a computer, or logs off the current user
  • SORT - takes input from a source file and sorts its contents alphabetically, from A to Z or Z to A - prints output on console
  • TREE - displays a tree of all subdirectories of the current directory to any level of recursion or depth
  • TITLE - sets the title displayed in the console window
  • SET - displays the list of environment variables on the current system

  • The > command is used to redirect the output to a specified file
  • The < command is used to run a command USING the specified file

Get the OpenURL of an Item in Primo New UI

I needed to view the OpenURL of an item in Primo New UI so that I could troubleshoot why one of our Alma General Electronic Services (ILLiad...