0

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?

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77

1 Answers1

1

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'
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • It still doesn't send the mail. How can I pass the command after navigating to desired path? E.g. should `start "" "cmd /k cd c:\Program Files\sendEmail-v156\" "echo foo"` navigate to c:\Program Files\sendEmail-v156\ and execute the echo command? – Mate Mrše Aug 24 '18 at 10:49
  • Please forget about cmd /k. Does the command execute when you manually run `sendEmail.exe -f sender@email.com -t receiver@email.com -s smtp.server.com:587 -xu myUsername -xp myPassword -m 'Test report text'` after you `cd` to the dir? – Gerhard Aug 24 '18 at 10:58
  • No problems, only a pleasure. – Gerhard Aug 24 '18 at 11:27