-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Don't know whether this is actually a bug or just a misunderstanding: If I try to use prompt() in calc shell script mode (i.e. from a script file read by option "-f") or when calling prompt() from a command line argument, it just prints its prompt but doesn't wait for input and always returns null. If I understand correctly, this is because calc closes stdin in both cases so prompt() obviously can't read anyhting.
Now: Is closing stdin in these cases intentional? At least to me (and to the person reporting this bug in Debian long ago) it was unexpected. How is prompt() supposed to be used then? Interactively from calc's command line it doesn't make too much sense either IMO.
I noticed that I can prevent stdin from getting closed using "-p". Is that how prompt() is supposed to be used in these cases?
If anybody can shed some light on the intentions here, I can probably submit a fix for either code or man page, depending on where the problem is.
To Reproduce
$ cat prompt_test.cal
#!/usr/bin/calc -q -f
n = prompt("Test> ");
if (isnull(n)) {
print("got null");
} else {
print("got " + n);
}
$ ./prompt_test.cal
Test> got null
$
Expected behavior
To get the expected behavior, change the first line in the script to:
#!/usr/bin/calc -q -p -f
Then prompt() actually waits for input and returns it:
$ ./prompt_test.cal
Test> INPUT
got INPUT
$
Execution environment (please complete the following information):
- OS: Linux
- OS version:
Linux gromit 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64 GNU/Linux
- OS distribution: Debian GNU/Linux 12 (bookworm)
- Calc Version: 2.15.0.1
- Shell and shell version:
GNU bash, version 5.2.15(1)-release