Hscript detecting if its on Windows or Linux?

   3615   5   0
User Avatar
Member
387 posts
Joined: July 2005
Offline
Hiya,

[ I figure there's a number of ways of doing this, and am wondering how people have approached/solved this… I have a solution, but… ]

When hscript runs, AFAIK, it doesn't know what operating system it's running on. It could be Linux, it could be Windows. It could be IRIX. When making a system call, with system(), it's important to get the pathname right: it could be “Xdir/file.py” or “/X/dir/file.py”. I've got a python script which will run in either environment, but there's two possible paths to the file - depending on whether it's running under Windows or Linux.

I'm looking for a neat way in hscript to detect the operating system type.

Running an external program to check the OS-type just “begs the question” about pathname syntax.

The ‘dumb’ approach seems to be to set an environment variable, like $ARCH, in the houdini setup script and then check the value in hscript. I note that $OS is already taken. I'm thinking “ARCH” because that's what Sun used to use back in the ol' days…

any thoughts?

Alternately, perhaps this is an RFE: could we have a script command called “arch” which returns the current os-type, being one of: irix, sunos, linux, windows, osx, and start.

ben.
''You're always doing this: reducing it to science. Why can't it be real?'' – Jackie Tyler
User Avatar
Member
4262 posts
Joined: July 2005
Offline
I wouldn't mind if the hscript command “version” displayed some of the build options. (Or maybe make a option to version (-v))
if(coffees<2,round(float),float)
User Avatar
Member
509 posts
Joined: July 2005
Offline
oh … now that's something I would definetly put in RFE as well …. I'll look forward for any update on this thread..

cheers.
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
User Avatar
Member
639 posts
Joined: July 2005
Offline
hello,

could you have query HOUDINI_OS env variable to find out your os? I thought there was an hscript or expression that checks for env variable outside of Houdini, but I could be wrong… (My brain isn't quite working right now… )
User Avatar
Member
557 posts
Joined: July 2005
Offline
It seems to me that this issue goes away when you can run python in Houdini, since that does have calls to do exactly this. Come to think of it, maybe you could use system() to call a python script that returnst the OS. In fact, I'm sure you could.
User Avatar
Member
387 posts
Joined: July 2005
Offline
Hiya,

(thanks for the replies!) IMHO “Using python” to work this out begs the question. The reason is you don't know whether to tell system() to run “Xthing/python.py” or run “/mnt/X/thing/python.py”. It's a chicken/egg thing.. Write one and try it. (?)

One approach might be to try both “C:” and “/mnt/…” in a script, and return the result which didn't fail (the script must cope with definite failure, as one of the tests will fail everytime). Another way might be to assume you have an execution PATH set, and so a Fully Qualified Pathname is not needed (FQP is one that starts with ‘C:’ or ‘/usr/local/’ etc). Though, the assumption makes it less portable, and is really avoiding the problem. The ideal solution (i think) would be to have something (a function or variable) built into houdini - so you don't have to use the operating system to discover its type.

TheUsualAlex had a good idea with ‘hconfig". Here’s a solution based on that:
#
# hscript
#
# output OS type
#
set hconfig_A=`system('hconfig -a')`
set os_type=`arg(substr($hconfig_A, index($hconfig_A, “HOUDINI_OS”), 100), 2)`
echo os type is $os_type
This script works in Linux and Windows. I called it “os” and put it in our HoudiniScriptPath.
Are there any other solutions? :-)
b.
''You're always doing this: reducing it to science. Why can't it be real?'' – Jackie Tyler
  • Quick Links