PixInsight Forum (historical)

Software Development => PCL and PJSR Development => Topic started by: georg.viehoever on 2010 July 29 12:03:01

Title: PJSR: How to determine if running on Windows?
Post by: georg.viehoever 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
Title: Re: PJSR: How to determine if running on Windows?
Post by: Juan Conejero 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!
Title: Re: PJSR: How to determine if running on Windows?
Post by: Juan Conejero 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.