batch-filecmdkatalon-studiomail-sendertest-reporting

Navigate to folder and run sendEmail from CMD


I'm building a simple email reporting system for my automated tests (in Katalon Studio).

When tests are failed, email gets sent using sendEmail.

    if (GlobalVariable.testSuiteStatus=='FAILED'){
      String bf = RunConfiguration.getProjectDir() + '/' + 'email.bat'
      Process p = Runtime.getRuntime().exec(bf)
    }

Email.bat contains:

cmd /c start cmd /k cd c:\\Program Files\\sendEmail-v156
sendEmail.exe -f sender@email.com -t receiver@email.com -s smtp.server.com:587 -xu myUsername -xp myPassword -m 'Test report text'

Each time this is run (or when I just doubleclick the bat file), only the first line gets executed.

So, how can I make this work?


Solution

  • You are telling cmd to open cmd again and cd, Which is what it does in a new window.. when you exit the new window, it will try and process sendmail from the working dir where you started the batch file from. Instead just try cd /d without the cmd /c or /k and run the executable from the batch directly:

    @echo off
    cd /d  "c:\Program Files\sendEmail-v156"
    start "" /wait sendEmail.exe -f sender@email.com -t receiver@email.com -s smtp.server.com:587 -xu myUsername -xp myPassword -m 'Test report text'