2

In java I would use: System.getProperty("os.name") to get Java to return the operating system. Is something similar possible in Rascal? My goal is to write a method to write text files to a folder that works OS-independent. Something like;

 public void writeTextFile(){
  if OS = "macOS" write text to "/Users/Shared/text.txt"
  if OS = "Windows" write text to "c:\text.txt"
 }
Richard
  • 294
  • 1
  • 7

2 Answers2

3

If you just use a home URL like home:///path/to/file the writeFile function will take care of the rest. There is also cwd:// for the current working directory and tmp:/// for the temp folder.

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
1

A more direct answer, but it will not lead to better code. You can use the API from util::SystemAPI:

rascal>import util::SystemAPI;
ok    
rascal>getSystemProperty("os.name")
str: "Mac OS X"

But, the other answer is better, since Rascal's loc data-type is supposed to provide a file system abstraction that works the same on all operating systems.

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26