Author Topic: PJSR: How to determine if running on Windows?  (Read 4610 times)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
PJSR: How to determine if running on Windows?
« on: 2010 July 29 12:03:01 »
Hi,

Is there a simple way to determined from PJSR if PI is running on Windows?

Background: I may need to massage some file names "x/y" to be "x\y", but only when running on Windows. I am giving these file names to an external windows process (via Console.execute()), not to PJSR itself.

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: How to determine if running on Windows?
« Reply #1 on: 2010 July 29 12:18:49 »
Hi Georg,

Use the following preprocessor directive:

#ifeq __PI_PLATFORM__ MSWINDOWS
...
#endif


The __PI_PLATFORM__ macro is automatically defined for all running PJSR scripts. It can have the following values:

FREEBSD
LINUX
MACOSX
MSWINDOWS


You can check for several platforms in a single directive. For example:

#ifoneof __PI_PLATFORM__ FREEBSD LINUX MACOSX
...
#endif


or, complementarily:

#ifnoneof __PI_PLATFORM__ FREEBSD LINUX MACOSX
...
#endif


Good luck with that new script!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: How to determine if running on Windows?
« Reply #2 on: 2010 July 29 12:23:27 »
By the way, you can also use the corePlatform property of the Global object:

if ( corePlatform == "MSWINDOWS" )
{
...
}


Although I personally think that dealing with these things at the preprocessor level is more efficient.

You can also use two static methods of the File object:

String File.unixPathToWindows( String path )
String File.windowsPathToUnix( String path )


to accomplish the task that you're trying to do.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/