Load file from command line, elaborate, print output

Questions and problems about using polymake go here.
paulcheung
Posts: 11
Joined: 06 Oct 2020, 03:45

Re: Load file from command line, elaborate, print output

Postby paulcheung » 28 Apr 2022, 17:37

I found it!!!!!!!!!!!!!!

\\wsl$\Ubuntu

I found this code from the following website

https://superuser.com/questions/1185033 ... -for-linux

This is what I need.......Thank GOOOOOOOOOOOOOOOOOOD!!!!!!!!!!!!!!

Also thank you for your patience.

User avatar
gawrilow
Main Author
Posts: 404
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 17:57

"C:" is a windows-specific notation, programs run under Linux subsystem do not understand it. Your home directory is physically located at C:\Users\qweas", it's where you can find your files using Windows tools, like file explorer. However, within your Linux subsystem, the home directory is mounted as "/home/qweas". You can simply use the "~" notation within polymake shell, e.g.

Code: Select all

save_data($p->FACETS, "~/mypoly.txt");
, then you'll find the resulting file at C:\Users\qweas\mypoly.txt.

Please note that save_data() creates a JSON file, not the plain output that you see when you use the print command in the polymake shell. If you want to redirect the output of the print command, you should type the following sequence:

Code: Select all

open MY_FILE, ">", "$ENV{HOME}/my_poly.txt" or die "can't create file: $!\n"; print MY_FILE $p->FACETS; close MY_FILE;
Unfortunately, "open" function does not understand the "~" notation directly, it's a small perl deficiency. That's why you should use the explicit reference to the HOME environment variable. save() and save_data() are polymake custom commands, they understand "~".

Please also keep in mind that Linux and Windows use different conventions for line ends in text files; viewing Linux files with some ancient Windows tools might be uncomfortable (the whole file might appear as a single long line).

paulcheung
Posts: 11
Joined: 06 Oct 2020, 03:45

Re: Load file from command line, elaborate, print output

Postby paulcheung » 28 Apr 2022, 18:38

You foresees both of my problems and you fixed it immediately!

Thank you so much! I was like, why my txt looks so weird. The code you provide works like magic!!

(I have no idea what those die , can't create file, / $!\n, mean..... This is something I would have never been able to figure out myself)

The notation ~ along with the code demonstration is super helpful as well! Now I have two ways to save my files.

Your help is immensely appreciated!!!

User avatar
gawrilow
Main Author
Posts: 404
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 18:57

"die" is the perl command throwing an exception, like "throw" in Java or "raise" in Python. The string after "die" is simply the text of the error message that would be displayed if this error occurs. \n is the end-of-line character, and $! is a magic perl variable containing a brief text describing a system error, for example "permission denied" or "no such file or directory".


Return to “Helpdesk”

cron