diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Shell.java b/bindings/java/src/net/hyperic/sigar/cmd/Shell.java index 1cd0ba4c..8c6c457b 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/Shell.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/Shell.java @@ -75,6 +75,9 @@ public class Shell extends ShellBase { registerCommandHandler("sysinfo", new SysInfo(this)); registerCommandHandler("time", new Time(this)); registerCommandHandler("who", new Who(this)); + if (SigarLoader.IS_WIN32) { + registerCommandHandler("service", new Win32Service(this)); + } try { //requires junit.jar registerCommandHandler("test", new SigarTestRunner(this)); diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Win32Service.java b/bindings/java/src/net/hyperic/sigar/cmd/Win32Service.java new file mode 100644 index 00000000..25e08ed9 --- /dev/null +++ b/bindings/java/src/net/hyperic/sigar/cmd/Win32Service.java @@ -0,0 +1,55 @@ +package net.hyperic.sigar.cmd; + +import java.util.Collection; + +import net.hyperic.sigar.SigarException; +import net.hyperic.sigar.win32.Service; +import net.hyperic.sigar.win32.Win32Exception; + +public class Win32Service extends SigarCommandBase { + + public Win32Service() { + super(); + } + + public Win32Service(Shell shell) { + super(shell); + } + + public String getSyntaxArgs() { + return "[name] [action]"; + } + + public String getUsageShort() { + return "Windows service commands"; + } + + protected boolean validateArgs(String[] args) { + return (args.length == 1) || (args.length == 2); + } + + public Collection getCompletions() { + try { + return Service.getServiceNames(); + } catch (Win32Exception e) { + return null; + } + } + + public void output(String[] args) throws SigarException { + String name = args[0]; + Service service = new Service(name); + if (args.length == 1) { + service.list(this.out); + } + else if (args[1].equals("start")) { + service.start(); + } + else if (args[1].equals("stop")) { + service.stop(); + } + else { + throw new SigarException("Unsupported service command: " + args[1]); + } + } +}