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.
Hscript detecting if its on Windows or Linux?
3615 5 0- ben simons
- Member
- 387 posts
- Joined: July 2005
- Offline
- wolfwood
- Member
- 4262 posts
- Joined: July 2005
- Offline
- VisualCortexLab
- 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.
cheers.
JcN
VisualCortexLab Ltd :: www.visualcortexlab.com
VisualCortexLab Ltd :: www.visualcortexlab.com
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
- craig
- Member
- 557 posts
- Joined: July 2005
- Offline
- ben simons
- 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.
(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