2

I would like to pass some code into Asymptote from the Windows command line. I see in the Asymptote manual the command line option:

-u, -user string        General purpose user string

I assumed this is what I should use so I created a DOS command as follows:

asy asyfile -u "int i = 5"

Then my asyfile.asy file contains write(i); resulting in an error no matching variable 'i'. Does anyone know if this is the intended use of the -user option? Is there another command-line option that would do what I need? Thanks!

2
  • 1
    In Linux you can use a pipe with the - option for Asymptote to read from stdin, like echo 'int i=5; include "asyfile.asy";'|asy -. This probably works in Windows as well (but I didn't test that).
    – Marijn
    Sep 8, 2022 at 12:19
  • @Marijn: Thanks for your comment! It inspired me to read further. While I'm sure your solution would work, I have discovered how to properly use the -u option as shown in my answer below.
    – James
    Sep 8, 2022 at 13:20

2 Answers 2

3

I would recommend defining i before usersetting():

int i;
usersetting();
write(i);

That way the user can enter either asy asyfile -u i=5 or asy asyfile on the command line.

1
  • 1
    Great idea, thanks! Also thank you for your work on Asymptote. It's my favorite programming language for smallish tasks. I only switch to C++ for more complex things. And a lot of my C++ projects create asymptote code to visualize their results.
    – James
    Sep 10, 2022 at 16:55
2

Marijn's comment inspired me to read the remainder of the Command-Line Options section in the manual. I discovered that I was misusing the -u option. I needed to add a usersetting(); command to my asyfile.asy file.

So asy asyfile -u "int i = 5" works as expected if my asyfile.asy file contains the following:

usersetting();
write(i);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .