PJSR: How to determine if running on Windows?

georg.viehoever

Well-known member
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
 
Hi Georg,

Use the following preprocessor directive:

Code:
#ifeq __PI_PLATFORM__ MSWINDOWS
...
#endif

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

Code:
FREEBSD
LINUX
MACOSX
MSWINDOWS

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

Code:
#ifoneof __PI_PLATFORM__ FREEBSD LINUX MACOSX
...
#endif

or, complementarily:

Code:
#ifnoneof __PI_PLATFORM__ FREEBSD LINUX MACOSX
...
#endif

Good luck with that new script!
 
By the way, you can also use the corePlatform property of the Global object:

Code:
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:

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

to accomplish the task that you're trying to do.
 
Back
Top