Sample LoadRunner script – pad a string with leading zeroes

When working on the previous article, Steven Woodcock found a problem where a string was losing it’s leading zeroes. They needed to be put back before his function worked properly and this is his solution to ensure that the output string was the correct length.

A working (ZIPPED) LoadRunner script can be downloaded so you can see this function in action.

strCharToPad – The String that requires to be padded out i.e. “123456”
cParamName – The name of the parameter you want the end value to be saved to
iValLength – The length you want the string to be padded out to i.e. 9
cValueToAdd – The character you want to pad the string out with, must be a single character i.e. “0”

Creates a LoadRunner parameter of a name specified in the input ‘cParamName’

int PadToX(char* cCharToPad, char* cParamName, int iValLength, char* cValueToAdd)

char cTemp[1024] = “”;
int iLoop = 0;
int iMainLoop = 0;
int iSubLoop = 0;

for(iMainLoop = 0; iMainLoop < iValLength; iMainLoop++)
if (iMainLoop == strlen(cCharToPad))
iLoop = iValLength – iMainLoop;
for (iSubLoop = 0; iSubLoop < iLoop; iSubLoop++)
strcat(cTemp, cValueToAdd);


strcat(cTemp, cCharToPad);
lr_save_string(cTemp, cParamName);


Creating uniquely named log files with details of running processes (TASKLIST)

Thanks to Scott Moore (at for the idea behind this article and to the owners of for their article on DOS string manipulation which I used to get the string concatenation right.

When running performance tests or any kind of performance analysis it can be useful to know the processes running on a PC or server which are consuming resources. The Windows command TASKLIST gives a list of currently running processes (basically a text based version of what the Task Manager process tab shows you).

TASKLIST screenshot

By piping the output of this file to a text file you can save details of the running processes for later analysis.

Scott’s article described a batch file which you could run before and after certain events such as batch processing or performance tests to create uniquely named log files containing the TASKLIST information. I had some difficulty getting his time and date stamps to work, possibly due to the timezone settings in Windows which “regionalise” the date and time environment variables. I’ve modified his original batch file to this one below which seems to work on UK PCs running Windows 7, Windows Vista and Windows XP.

Sample Code

for /f “tokens=1-3 delims=/ ” %%d in (“%date%”) do set d=%%d-%%e-%%f

for /f “tokens=1-3 delims=:” %%d in (“%time%”) do set t=%%d%%e

set timestr=%d:~6,4%%d:~3,2%%d:~0,2%-%t:~0,2%%t:~2,2%

tasklist /FO CSV > TASKLIST_Logfile_%timestr%.csv


This creates a CSV file named TASKLIST_Logfile_YYYYMMDD-HHMM.csv formatted like the sample below.

Sample Output

“Image Name”,”PID”,”Session Name”,”Session#”,”Mem Usage”

“System Idle Process”,”0″,”Services”,”0″,”24 K”

“System”,”4″,”Services”,”0″,”95,672 K”

“smss.exe”,”272″,”Services”,”0″,”64 K”

“csrss.exe”,”408″,”Services”,”0″,”2,484 K”

“csrss.exe”,”484″,”Console”,”1″,”73,224 K”

“wininit.exe”,”496″,”Services”,”0″,”172 K”

“avgchsva.exe”,”508″,”Services”,”0″,”25,816 K”



UNIX command reference

Environment Control

Command                     Description
cd d                             Change to directory d
mkdir d                        Create new directory d
rmdir d                         Remove directory d
mv f1 [f2...] d               Move file f to directory d
mv d1 d2                      Rename directory d1 as d2
passwd                         Change password
alias name1 name2       Create command alias (csh/tcsh)
alias name1="name2"    Create command alias (ksh/bash)
unalias name1[na2...]    Remove command alias na
ssh nd                          Login securely to remote node
exit                              End terminal session
setenv name v              Set env var to value v (csh/tcsh)
export name="v"           Set environment variable to value v (ksh/bash)

Output, Communication, & Help

Command                     Description
lpr -P printer f               Output file f to line printer
lp -d printer f                Output file f to line printer
script  [f]                      Save terminal session to f
exit                              Stop saving terminal session
mailx username             Send mail to user
man name                     Unix manual entry for name

Process Control

Command                     Description
CTRL/c *                      Interrupt processes
CTRL/s *                      Stop screen scrolling
CTRL/q *                      Resume screen output
sleep n                         Sleep for n seconds
jobs                             Print list of jobs
kill %                           Kill job n
ps                                Print process status stats  
kill  -9 n                       Remove process n
CTRL/z *                      Suspend current process
stop  %n                      Suspend background job n
cmmd&                        Run cmmd in background
bg  [%n]                      Resume background job n
fg  [%n]                       Resume foreground job n
exit                              Exit from shell

Environment Status

Command                     Description
ls  [d]  [f...]                  List files in directory
ls -1  [f...]                    List files in detail
alias  [name]                Display command aliases
printenv  [name]           Print environment values
quota                           Display disk quota
date                             Print date & time
who                              List logged in users
whoami                        Display current user
finger  [username]        Output user information
chfn                             Change finger information
pwd                              Print working directory
history                          Display recent commands
! n                               Submit recent command n

File Manipulation

Command                     Description
vi  [f]                            Vi fullscreen editor
emacs  [f]                     Emacs fullscreen editor
ed  [f]                          Text editor
wc  f                             Line, word, & char count
cat  f                            List contents of file
more  f                         List file contents by screen
cat f1 f2 >f3                  Concatenates f1 & f2 into f3
chmod mode f               Change protection mode of f
cmp f1 f2                      Compare two files
cp f1 f2                         Copy file f1 into f2
sort f                            Alphabetically sort f
split  [-n]  f                   Split f into n-line pieces
mv f1  f2                      Rename file f1 as f2
rm f                             Delete (remove) file f
grep 'ptn'  f                  Outputs lines that match ptn
diff f1 f2                       Lists file differences
head f                          Output beginning of f
tail f                            Output end of f

Abbreviations used in this document

CTRL/x       hold down control key and press x
d               directory
env            environment
f                filename
n               number
nd             computer node
prtr            printer
ptn            pattern
var            variable
[y/n]         yes or no
[]             optional arg
...             list