How to know the service status || how to start service in gradle script?

Hi All,

I want to start a service for that I am using below code snippet

task startHttpService(dependsOn: EacProperties) << {

exec { commandLine=[‘cmd’,’/c’,“Sc start “endecahttpservice””] } }

But if the service is already in running at that time build is failed.

First I want to know the status of the service if it is in running no need to start if it is stopped then only I want to start the service.

Could you please any body help me to write script to verify the service status and based on that status to run the service.

Could you please any body provide script for that .