On Fri, Aug 22, 2008 at 2:23 PM, Andy Thomson <[EMAIL PROTECTED]> wrote:
> I had proposed a change a while back to allow for new SITE commands. I have
> added quite a few using it: CHMOD, UTIME, DUAL [provides MD5 & SHA1 hashes
> on a file or all files in a directory], and some custom ones specific to my
> needs.
>
> Maybe it can posted/added as an "extra" for people that would want the
> ability to add custom SITE commands? I would supply the ones above and a
> generic template on how to do it.
Sure, or for those that doesn't cause any outrageous dependencies or
other problems, I'll be happy to include them in core. For those which
are not documented elsewhere, we should provide detailed
documentation.
> One of the key tasks is to detect the OS platform the service is running one
> and call the appropriate OS command shell & command. There was a good
> article about 7-8 years ago on this, not much has changed from the JVM
> perspective [sad].
Yeah, I'm one of th commiters for the commons-exec project so I'm
sadly aware of this problem :-)
> Here is a snippet from the code:
>
> String osName = System.getProperty("os.name");
> String[] cmd = new String[3];
>
> if (osName.equals("Windows 95")) {
> cmd[0] = "command.com";
> cmd[1] = "/C";
> cmd[2] = cmdline;
> } else if (osName.contains("Windows")) {
> cmd[0] = "cmd.exe";
> cmd[1] = "/C";
> cmd[2] = cmdline;
> } else if (osName.equals("Linux")) {
> cmd[0] = "sh";
> cmd[1] = "-c";
> cmd[2] = cmdline;
> }
Of course, keeping this up-to-date with all platforms is a pain.
Especially since developers usually have limited access to the more
obscure platforms. This is a problem with for example the VMS code in
commons-exec.
> The "cmdline" is a string that holds the actual command and it's parameters:
> "/bin/chmod 755 somefile". All error messages are passed back, works same
> as command line.
Yeap, but is there such commands on for example Windows? In my
understanding, on Windows you need to use the Win32 API, for example
using JNI.
> Not sure what is the best way to get this code introduced? Maybe just post
> it somewhere and reference it?
Attach it to a JIRA issue and make sure to tick the okay-for-inclusion
radio button and we can have a look at it.
/niklas