Reading and executing M2 code in Linux subsystem for Windows

73 views
Skip to first unread message

Kieran Bhaskara

unread,
Jan 11, 2022, 10:04:21 AM1/11/22
to Macaulay2
Hello,

I am using M2 with the Linux subsystem for Windows. Is there an easy way I can load and execute M2 code that I have saved to a text file? The documentation I can find seems to pertain only to M2 on Linux machines.

Best,
Kieran

Daniel R. Grayson

unread,
Jan 12, 2022, 10:31:38 AM1/12/22
to Macaulay2
Yes, that's what the function "load" is for.

Macaulay2 is intended to work the same way under every operating system, and the documentation describes that way.



Kieran Bhaskara

unread,
Jan 12, 2022, 10:46:10 AM1/12/22
to Macaulay2
The issue is I don't know where the file should be saved for it to open. My current directory is /root/, and path is {./, .Macaulay2/code/, .Macaulay2/local/share/Macaulay2/, /usr/share/Macaulay2/}. Where does this correspond in the Windows directory?

Best,
Kieran

Daniel R. Grayson

unread,
Jan 12, 2022, 10:59:24 AM1/12/22
to Macaulay2
I don't know where (or whether) Linux Subsystem files can be located under Windows -- maybe a user of Windows can provide that info.

It might be better to create the file with a Linux Subsystem application such as emacs -- then you would know where the file is.

Typically you would create the file first, and then start M2 running in the same directory.  The presence of "./" on the path then
ensures that your file can be found when "load" is used to load it.  Within M2, you can see what your current directory is
with "currentDirectory()" -- that's what "./" expands to.  In your case, it seems you've started M2 in your home directory, as
that's where the subdirectory ".Macaulay2" is.

If you're using emacs, as recommended, you can delete the buffer "*M2*" if it exists, visit the file you wish to run, and then start M2 running with f12.
It will start running in the same directory as the file.





jche...@gmail.com

unread,
Jan 12, 2022, 12:43:42 PM1/12/22
to Macaulay2
I believe the WSL2 filesystem is virtual, and does not correspond to a physical location within Windows (this was not the case for WSL1, though one should really upgrade to WSL2.)

Nonetheless, within WSL2, you can certainly access the Windows drive - on my installation it is under "/mnt/c", which is the same C: drive that Windows sees. In my opinion it is easiest (for interoperability) to change the working directory ("cd") in Linux to a physical location that Windows can access, such as your Documents folder (e.g. /mnt/c/Users/username/Documents). You can then start M2 (or emacs) in this directory, and then load files as Dan said.

Justin

Kieran Bhaskara

unread,
Jan 12, 2022, 10:54:25 PM1/12/22
to Macaulay2
Hi Justin,

Thank you. How do I check where the Windows Drive is and change the working directory?

Kieran
Reply all
Reply to author
Forward
0 new messages