Any idea to read its output from tcl?
Hello,
I have a simple java program that has a few println statements. I open a
pipe command to this java app. It runs but I can't seem to get any of
its output. I have tried several variations of -blocking/-buffering
options with no avail. Same thing done with a tcl script runs fine.
The open command is:
% set fd [open "|java Test" r]
Any idea to read its output from tcl?
Any idea to read its output from tcl?
Can you post a minimal, reproducible example? The following works just fine for me:
% java --version
openjdk 17.0.6 2023-01-17
OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode)
% package req Tcl
8.6.13
% set ch [open "|java Test" r]
file5
% read -nonewline $ch
Tested!
% close $ch
-------------------%<-------------------
set ch [open "|java Test" r]
set data [read -nonewline $ch]
close $ch
puts "GOT IT: $data"
-------------------%<-------------------
saitology9 <[email protected]> wrote:
-------------------%<-------------------
set ch [open "|java Test" r]
Try adding:
fconfigure $ch -buffering line
or
fconfigure $ch -buffering none
here.
On 6/12/2023 12:54 PM, Rich wrote:
saitology9 <[email protected]> wrote:
-------------------%<-------------------
set ch [open "|java Test" r]
Try adding:
fconfigure $ch -buffering line
or
fconfigure $ch -buffering none
here.
Thanks, Rich. I have added different buffering and blocking options, including your suggestions above, alone and together, with no change in
the result.
I see that stefan was using "openjdk" whereas I have plain "jdk".
Perhaps that is the difference? I will try to install it later and see
how that goes.
saitology9 <[email protected]> wrote:
I see that stefan was using "openjdk" whereas I have plain "jdk".
Perhaps that is the difference? I will try to install it later and see
how that goes.
That would be my next suggestion of where to look, as there are *two*
buffers on a TCP connection. Buffering at the source, and buffering
at the destination.
saitology9 <[email protected]> wrote:
-------------------%<-------------------
set ch [open "|java Test" r]
Try adding:
fconfigure $ch -buffering line
or
fconfigure $ch -buffering none
here.
identifiers I get are different from yours too: "file3c6bd18" vs "file5". This is on Windows, Tcl/Tk 8.6.
So, essentially it is a Windows-issue, and likely not one of buffering,
or openjdk versus oracle's jdk.
Does it work on command line (cmd.exe) to redirect java's output
to a file? If not, then it might use a specific windows-api to
output its "stdout" directly to the console, ignoring redirection.
There's also a faint chance, that it will do it dependent on
current locale... (e.g. it may use a special api to output utf-8,
which the typical "DOS-box" running cmd.exe otherwise doesn't
display correctly.
On 6/13/2023 7:42 AM, Andreas Leitgeb wrote:
So, essentially it is a Windows-issue, and likely not one of buffering,Thank you for the info. Here I strongly suspect it was an openjdk vs.
or openjdk versus oracle's jdk.
oracle jdk issue as switching to openjdk solved the issue immediately.
Does it work on command line (cmd.exe) to redirect java's outputYes, it always worked from the command line (cmd.exe), with or without
to a file? If not, then it might use a specific windows-api to
output its "stdout" directly to the console, ignoring redirection.
output redirection.
There's also a faint chance, that it will do it dependent onScary. I think the dos cmd replacement has a switch that specifies
current locale... (e.g. it may use a special api to output utf-8,
which the typical "DOS-box" running cmd.exe otherwise doesn't
display correctly.
whether the output is in plain ascii or utf-8 and maybe cmd supports it too.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (3 / 13) |
| Uptime: | 00:39:54 |
| Calls: | 12,097 |
| Calls today: | 5 |
| Files: | 15,003 |
| Messages: | 6,517,858 |