Problem contactenating a string
Posted: 05 Apr 2022 05:19
I have a batchfile that will assemble a command line passed on passed parameters.
I call the code as follows:
The selective concatenation is not taking place.
I tried various approaches but never getting the expected result.
Below is the output I get from executing the code
SET ExecBase="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message"
SET TempStr=
if NOT "email@outlook.com" == "NA" (
SET TempStr="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com
SET ExecBase=
)
if NOT "C:\Temp\File1.txt" == "NA" (
SET TempStr= -a "C:\Temp\File1.txt"
SET ExecBase="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com
)
if NOT "C:\temp\file2.txt" == "NA" (
SET TempStr="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com -a "C:\temp\file2.txt"
SET ExecBase= -a "C:\Temp\File1.txt"
)
Thanks
Code: Select all
REM Parameters:
REM To (required)
REM To (Optional) - NA to indicate empty
REM Subject (required)
REM Message (required)
REM AttachFile1 (optional) - NA to indicate empty
REM AttachFile2 (optional) - NA to indicate empty
SET EmailTo1=%~1
SET EmailTo2=%~2
SET EmailSubject=%~3
SET EmailMessage=%~4
SET EmailFile1=%~5
SET EmailFile2=%~6
if "%EmailTo1%"=="" GOTO MissingParams
if "%EmailSubject%"=="" GOTO MissingParams
if "%EmailMessage%"=="" GOTO MissingParams
REM Check that EmailFile2 is not null. This guarantees that all other parameters are populated
if "%EmailFile2%"=="" GOTO MissingParams
SET tmp-File=d:\temp\sendemail.log
IF NOT EXIST d:\temp\NUL SET tmp-File=c:\temp\sendemail.log
SET ExecBase="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l %tmp-File% -t %EmailTo1% -u "%EmailSubject%" -m "%EmailMessage%"
SET TempStr=
if NOT "%EmailTo2%"=="NA" (
SET TempStr=%ExecBase% -t %EmailTo2%
SET ExecBase=%TempStr%
)
if NOT "%EmailFile1%"=="NA" (
SET TempStr=%ExecBase% -a "%EmailFile1%"
SET ExecBase=%TempStr%
)
if NOT "%EmailFile2%"=="NA" (
SET TempStr=%ExecBase% -a "%EmailFile2%"
SET ExecBase=%TempStr%
)
ECHO %BaseFile%
GOTO :End
Code: Select all
SendFailOver.cmd email@gmail.com email@outlook.com "This is a subject" "this is a message" "C:\Temp\File1.txt" "C:\temp\file2.txt"
I tried various approaches but never getting the expected result.
Below is the output I get from executing the code
SET ExecBase="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message"
SET TempStr=
if NOT "email@outlook.com" == "NA" (
SET TempStr="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com
SET ExecBase=
)
if NOT "C:\Temp\File1.txt" == "NA" (
SET TempStr= -a "C:\Temp\File1.txt"
SET ExecBase="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com
)
if NOT "C:\temp\file2.txt" == "NA" (
SET TempStr="C:\Program Files (x86)\sendEmail\sendEmail.exe" -l d:\temp\sendemail.log -t email@gmail.com -u "This is a subject" -m "this is a message" -t email@outlook.com -a "C:\temp\file2.txt"
SET ExecBase= -a "C:\Temp\File1.txt"
)
Thanks