Unterschiedliche BS abfragen

Hi,
wie fragt ihr im Programm auf unterschiedliche Betriebssysteme ab? bei mir ist das Problem, dass ich externe Programme ausführen lassen möchte und die über die Konsole starte.

if (System.getProperty("os.name").compareToIgnoreCase("windows") \> 0)
{
 if ( System.getProperty("os.name").compareToIgnoreCase("nt") \> 0 
||
 System.getProperty("os.name").compareToIgnoreCase("2000") \> 0 )
 {
 command = "cmd.exe"; //win NT, 2000
 }
 else
 command = "command.com"; //win 95, 98, ME etc. 

 command = command + " /C ";
}

hier fehlt mir zb noch linux, unix, os

steffi

Moin

wie fragt ihr im Programm auf unterschiedliche Betriebssysteme
ab?

So jedenfalls nicht:

compareToIgnoreCase (String S) returns a negative integer, zero, or a positive integer as the the specified String is greater than, equal to, or less than this String, ignoring case considerations.

versuchs mit (String.toLowerCase().indexOf (toTest.toLowerCase()) == -1))

hier fehlt mir zb noch linux, unix, os

Bei linux kommt immer „linux“ vor, unix könnte man über die IBM-HP abfragen (wobei manche Unixe Linux nachmachen und dadurch die linux-VM’s auch unter unix-systemen laufen. (Mit od meinst du OSX, also Mac, oder ?) Solaris fehlt in deiner Liste.

cu

Moin

wie fragt ihr im Programm auf unterschiedliche Betriebssysteme
ab?

So jedenfalls nicht:

Aber so ähnlich :wink:
Ich habe es bei einer meiner Anwendunge hierüber gelöst. Es fehlt aber noch Win98 und ME.

 /\*\*
 \* Get the default shell command.
 \*
 \* @return default shell command
 \*/
 public String getDefaultShell() {
 final String osName = System.getProperty("os.name");
 final String shellCommand;

 if ("Windows NT".equals(osName) || "Windows XP".equals(osName)) {
 shellCommand = "cmd.exe /C";
 } else if ("Windows 95".equals(osName)) {
 shellCommand = "command.com /C";
 } else {
 shellCommand = null;
 }

 return shellCommand;
 }

compareToIgnoreCase (String S) returns a negative integer,
zero, or a positive integer as the the specified String is
greater than, equal to, or less than this String, ignoring
case considerations.

versuchs mit (String.toLowerCase().indexOf
(toTest.toLowerCase()) == -1))

hier fehlt mir zb noch linux, unix, os

Bei linux kommt immer „linux“ vor, unix könnte man über die
IBM-HP abfragen (wobei manche Unixe Linux nachmachen und
dadurch die linux-VM’s auch unter unix-systemen laufen. (Mit
od meinst du OSX, also Mac, oder ?) Solaris fehlt in deiner
Liste.

Die sind aber für diesen Fall nicht relevant, weil sie kein spezielles Shel Kommando benötigen.

/dirk