On Thu, May 05, 2022 at 08:37:27AM +0200, Ralf Hemmecke wrote:
> >Looking into 'sb-ext::run-program' docs shows that 't' means inheriting
> >standard input, output and error output from current process, which at
> >least in some cases seem to be right thing.
>
> The current process is FRICASsys. So it goes to the stdout and stderr of
> whatever FRICASsys gets. Do I understand this correctly?
Yes. On my machine current FRICASsys has process number 7985.
Doing 'ls -l /proc/7985/fd' I see:
lrwx------ 1 hebisch hebisch 64 May 5 11:04 0 -> /dev/pts/2
lrwx------ 1 hebisch hebisch 64 May 5 11:04 1 -> /dev/pts/2
lrwx------ 1 hebisch hebisch 64 May 5 11:04 10 -> socket:[22234]
lrwx------ 1 hebisch hebisch 64 May 5 11:04 11 -> socket:[22235]
lrwx------ 1 hebisch hebisch 64 May 5 11:04 12 -> socket:[24271]
lrwx------ 1 hebisch hebisch 64 May 5 11:03 2 -> /dev/pts/2
lrwx------ 1 hebisch hebisch 64 May 5 11:04 3 -> /dev/tty
So standard error, that is descriptor 2 is connected to pseudotrminal
/dev/pts/2. You can also see that on file descriptor 3 sbcl tries
do dig real terminal. Preferably nothing should do to file
descriptor 3, while 2 is fine.
> However, this is, of course not what I want. In particular, when a user
> types ")sys pwd" he wouldn't get that information at all (with (*)),
> because then the process is whatever Jupyter does internally. It does
> certainly NOT appear on the console from where I start "jupyter notebook".
>
> This problem with stdout of )sys commands is one of the reasons why we
> added such an option with gnome-terminal into the fricaskernel.py.
>
> >You say that you want to catch error output. But what errors?
>
> (1) -> )sys foo
> /bin/sh: 1: foo: not found
>
> That is visible in a ordinary fricas session but not in jfricas unless I
> start OBEY with the ":error *standard-output" (or *error-output*) option.
>
> >A little grepping of sources shows that currently one main use case for
> >OBEY is starting external editor, where inherited file descriptors seem to
> >be correct (and in jFriCAS you probably do not want to support this or
> >offer replacement compatible with Web interface).
>
> Hmmm... maybe I should even disallow ")edit". Oh... no need... even in
> the console fricas it says.
>
> (1) -> )edit "foo.input"
>
> Warning: environment variable FRICASEDITOR not set.
> Launching 'more' in an 'xterm'.
> Press space to continue, 'q' to quit.
>
> )edit is nowadays only necessary for people working completely in
> ASCII-mode and do not now about Ctrl-Z to stop a process, do something
> else (like editing) and come back into the fricas console. That pretty
> much sounds like ")edit" can be removed, because I do not see a use case
> anymore.
I make almost no use of ')system' (and the same for ')edit'). However
this is no reason to break them.
> >Other use case are calls to few system commands where errors are
> >_not_ expected. If some unexpected error pops up it is debatable
> >where message should go, but resonable convention is that those
> >errors should go to FRICASsys standard error.
>
> Not in the case of jfricas. The jupyter notebook is the only visible
> form of communication. I have no control over how fricaskernel.py (and
> therefore FRICASsys) is started. No idea what jupyter does with stdout
> and stderr and from where I could fetch that output.
I would hope that there is some way, at least for debugging. But
I am not going to search for this.
> >In particular, I not sure what you are doing with OBEY that you need
> > to catch standard output?
>
> I want ")sys pwd" to show me something. We have included ")!
> some-shell-command" in jfricas, just because we didn't know how to catch
> )sys output", but ")! pwd" and ")sys pwd" do not give the same result,
> because ")!" always starts a new shell. Maybe with now having a way that
> )sys can output something, ")!" should probably go away or be synonymous
> to )sys.
>
> >To put it differently, ATM you can launch text editor or a shell via
> > ')system' command and it almost works (there is some breakage due to
> > clef/rlwrap interfering, AFAICS without sman it works fine). This is not
> >very important use case, but it is nice to keep what works working. OTOH
> >in jFriCAS I would _not_ expect current ')system' to work, at least not
> >without some alternative implementation.
>
> With the modified OBEY, it works fine at least for what I have seen so
> far. I do not claim that I have tested it well enough, but I am happy
> that ")sys pwd" works. I do not want to do fancy stuff and when
> eventually jFriCAS is mature enough and we can offer a server and a
> webinterface to access fricas from the internet, we probably want to
> turn off )sys and other dangerous things completely. But that shouldn't
> concern us now in the local use case.
For the record: you can do whatever dangerous you like just at
Spad/Lisp level. You would have to disable quite a lot of things
and do seriouos security audit to allow untrusted user at FriCAS
command prompt. OTOH I do not see if ')system' makes sense via
web. And clearly in remote case ')edit' needs different
implementation.
> >>For jfricas it wouldn't probably matter since I anyway set
> >>*error-output* to *standard-output*.
> >>
> >>In fact, browsing through the FriCAS code, it seems that *error-output*
> >>is only used in the lisp optimizer.
> >
> >Well, currently when we generate Lisp code Lisp '*standard-output*' is
> >redirected to file. But we definitely do not want error messages
> > going to '*standard-output*': some messages are just warning, but
> >if emmited to file would make it syntactiacally incorrect.
>
> Hmmm... here the question is when does the optimizer jump in? Only at
> the time when fricas is build or also when a user defines a function and
> that function is compiled at its first use? Only the second case would
> be problematic. For the first we could let OBEY be as it is now.
Main case is Spad compilation (which somewhat advanced user is
supposed to do). The same my apply to situations when w generate
output to files. Arguably we should not do this, but ATM main
way to get output in desired place (including files) is via
redirection. Fortunately, OBEY is now used less than in the
past so normally there should be no OBEY in middle of compilaton".
OTOH uncheckable conditions like "you should not call OBEY in
middle of compilaton" are not nice, so using *error-output*
for OBEY _normally_ is better.
> >User normally does not look at generated file so error messages
> >emmited to file are effectively lost.
>
> In the beginning jfricas collected output from different streams in
> different stores. But that was a problem with the order in which jfricas
> would show the total output, because a cell can potentially contain
> multiline input like
>
> foo1
> )set output algebra off
> )set output tex on
> foo2
> )sys pwd
> )set output algebra on
> )set output tex off
> foo3
>
> I wouldn't want to see the output of foo1 and foo3 before the output of foo2
> in tex. So everything in jfricas goes to *standard-output*, but comes with
> begin and end markers that tell fricaskernel.py in which format it should be
> presented. Maybe not perfect, but works.
OK.
> >BTW: As I wrote Saturn (Texexplorer) had notebook interface. While code
> >supporting Saturn is removed now you can look at past versions to see how
> >they handled tricky problems. In particular
> >i-output.boot was modified to behave as needed by Saturn. IIRC this
> >included TeX output of types and handling of line numbers.
>
> Tex output is completely uninteresting for jfricas. We have FormatMathJax
> for that.
Well, one who does not read code written by others will repeat their
mistakes.
On most crude level if you looked at Saturn code you will see that
there were a lot of conditionals, code would do sligthly different
thing for Saturn. In particular you should have flag signaling
other part of FriCAS that it runs for jFriCAS (probably you already
have it). If you want different behaviour from OBEY for jFriCAS,
than test flag in OBEY and do what needed.
> >BTW2: My impression is that in Saturn "unexpected" error messages went to
> >AXIOMsys console.
>
> The question is what is the "AXIOMsys console"? Other question is when I
> type ")sys foo" and get an error message like "/bin/sh: 1: foo: not found",
> then I wouldn't count that as an error of the ")sys" command, but rather a
> valid output of what I asked for. If ")sys" itself or any other comman finds
> weird behaviour and wants to report (to FriCAS developers), then it is
> questionable where this should go. But I would even argue that it should be
> visible to the user with clear message that he/she should report to the
> fricas-devel list.
As I wrote, ')system' is somewhat special. Arguably tying its output
to Lisp *standard-output* is wrong. There is more subtle question of
tying error output of ')system' to FRICASsys standard output, but
Lisp *standard-output* can point to quite different place than
FRICASsys standard output (or place where you are trying to redirect
*standard-output*). But if jFriCAS can not implement 'OBEY' as
intended, than your approach is reasonable to get going. However
this should be condidtional to jFriCAS.
Sorry that my message got so long. Main point is that IMO redirection
that you want for jFriCAS ATM should be conditional.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/20220505135759.GA11527%40fricas.math.uni.wroc.pl.