[PROJ] cs2cs in a pipe
Even Rouault
even.rouault at spatialys.com
Tue Nov 17 03:42:26 PST 2020
Roger,
> I am doing some programming inTcl (I like it - don't judge:)
>
> I would like to project some lat/long values to Sweref99. Normally I do
> this via the C API. But now I want to do so in a Tcl script. I want to
> start the program and, for each line I write to it (it's standard input), I
> would like to immediately read the results. And just keep doing this. I do
> not want to start the program for each set of values as that would take too
> long.
>
> I have no trouble getting the cs2cs program to run. But I do not get values
> reported. I see when I trace cs2cs when it is running in my script (via
> strace that shows all system calls), cs2cs is correctly reading a line of
> values to project. However, it never writes anything. It is just in another
> read call waiting for the next line.
>
> Should I expect cs2cs to report each projection as each line is read? I
> could not think that it buffered them. But maybe the output is buffered via
> whatever call cs2cs is doing to list results? If that is the case, is there
> some way to tell cs2cs to flush the results after each projection is
> complete?
cs2cs reports the result with a printf(stdout) with a newline character.
According to https://stackoverflow.com/a/4201325 , stdout is line buffered for
an interactive terminal (that is each newline character will cause it to be
flushed). But in your pipe case, stdout isn't interactive, hence it doesn't
get flushed at each newline character
Fixed per https://github.com/OSGeo/PROJ/pull/2429
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the PROJ
mailing list