• Instead of using the command shell to see if the SQL Agent Service is running.  You could use the following command.

    EXEC master..xp_servicecontrol QueryState, SQLServerAgent