lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

See my Hamster and/or Lumikki projects on the net. They detect the OS based on 'uname' and environment variables, which has proven to be harmless, accurate and extensible.

Frank Küster kirjoitti 27.6.2007 kello 22:49:


I'd like to detect in a lua script on which (kind of) operating system
I'm running, in order to provide sensible defaults for calls to external
programs (viewers, actually).  Thinking about OS X, I considered

if os.execute('nothere 2>/dev/null') / 256 == 127 then
   print("does not exist")

and got the answer

/dev/null works on UNIX, on Windows it's nul (and does not appear in
the filesystem).  However, another nice solution would be to walk
through the path (os.getenv("PATH")).  With other words, write a
function which does the same as the UNIX which command.

Note that paths are separated by ";" on Windows instead of ":".

Which brings me to the question, is there some code snippet which I
could use?

Regards, Frank

Frank Küster
Single Molecule Spectroscopy, Protein Folding @ Inst. f. Biochemie, Univ. Zürich
Debian Developer (teTeX/TeXLive)