Execute the command from a Text file directly

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

Execute the command from a Text file directly

Postby paulcheung » 24 Feb 2023, 05:38

Hi, I am an absolute newbie to programming. I wonder whether I can execute the commands from a Text file directly

Suppose that has a text file that
1) is called: example.txt
2) is located at: \\wsl$\Ubuntu\home\myname\example.txt
3) has the following two lines of commands

$p = new Polytope(POINTS=>[[1, 1, 2, 3,], [1, 4, 5, 2,], [1, 4, 5, 2,],]);
print $p->FACETS;

Is there any way that I can use the interactive session to call out the text file and execute these commands? Thank you!

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

Re: Execute the command from a Text file directly

Postby gawrilow » 24 Feb 2023, 09:48

Yes, you can use the script function:

Code: Select all

script("example.txt");
In case your current working directory is not your home dir:

Code: Select all

script("~/example.txt");
You can learn various tips and tricks regarding scripting in this chapter of documentation.

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

Re: Execute the command from a Text file directly

Postby paulcheung » 24 Feb 2023, 17:26

Thank you very much for the reply! I am still having some trouble.

When I type in

Code: Select all

script("example.txt");
It gives the error message.

ERROR: Package "Polytope" does not exist at /home/myname/example.txt line 1.

Yet, the two command lines work perfectly if I copy and paste them into the interactive sessions. So I tried to read from the chapter of documentation, and I added in the preamble so that the text file now contain

Code: Select all

use application "NAME"; $p = new Polytope(POINTS=>[[1, 1, 2, 3,], [1, 4, 5, 2,], [1, 4, 5, 2,],]); print $p->FACETS;
And then I type script("example.txt") again, it gives another error message (two lines)..

ERROR: Unknown application NAME
BEGIN failed--compilation aborted at /home/myname/example.txt line 1.

I don't know how to fix this... I sincerely appreciate it you could help me. Thank you!!

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

Re: Execute the command from a Text file directly

Postby paulcheung » 24 Feb 2023, 17:48

Ohhhhhh, I guess I just figured it out from your replies in other posts. I should type this in the text instead

Code: Select all

use application "polytope"; $p = new Polytope(POINTS=>[[1, 1, 2, 3,], [1, 4, 5, 2,], [1, 4, 5, 2,],]); print $p->FACETS;
Thank you anyway! :lol:


Return to “Helpdesk”