Search code examples
rascal

Can Rascal return the operating system in method?


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"
 }


Solution

  • 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.