How to capture screen output?
How to capture screen output?
Hello!
The following line in a programme
Exec ("gdallocationinfo"," -valonly -wgs84 " & weatherfile & " 125.25 37.7 ")
outputs a value (say, 46!) to the console.
How can I "import" or "intercept" this value and use it in my programme?
Many thanks!
The following line in a programme
Exec ("gdallocationinfo"," -valonly -wgs84 " & weatherfile & " 125.25 37.7 ")
outputs a value (say, 46!) to the console.
How can I "import" or "intercept" this value and use it in my programme?
Many thanks!
-
- Posts: 1002
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: How to capture screen output?
Many thanks, Roland. This is exactly what I was looking for!
I just tried this
DIM AS STRING GDALLOCATIONINFO, LIN, WEATHERFILE="./ECMWF_dekads/int_1989-2015/Rain/int_19890101rf.img"
DIM AS BYTE CONSOLE
CONSOLE=FREEFILE
GDALLOCATIONINFO = "gdallocationinfo -valonly -wgs84 " & weatherfile & " 125.25 37.7 "
OPEN PIPE GDALLOCATIONINFO FOR INPUT AS #CONSOLE
LINE INPUT #CONSOLE, LIN
PRINT LIN
which produces the desired result.
Is there a risk that I won't catch all the output if I don't use the DO .... LOOP UNTIL EOF() ?
René
I just tried this
DIM AS STRING GDALLOCATIONINFO, LIN, WEATHERFILE="./ECMWF_dekads/int_1989-2015/Rain/int_19890101rf.img"
DIM AS BYTE CONSOLE
CONSOLE=FREEFILE
GDALLOCATIONINFO = "gdallocationinfo -valonly -wgs84 " & weatherfile & " 125.25 37.7 "
OPEN PIPE GDALLOCATIONINFO FOR INPUT AS #CONSOLE
LINE INPUT #CONSOLE, LIN
PRINT LIN
which produces the desired result.
Is there a risk that I won't catch all the output if I don't use the DO .... LOOP UNTIL EOF() ?
René
-
- Posts: 1002
- Joined: Nov 24, 2011 19:49
- Location: France
- Contact:
Re: How to capture screen output?
If the answer has only one line, I imagine that it should work without looping.wergosum wrote:Is there a risk that I won't catch all the output if I don't use the DO .... LOOP UNTIL EOF() ?
Happy Easter!
Re: How to capture screen output?
Yes but after the reading of the first string, it is better to close the process:
Close #CONSOLE
Close #CONSOLE
Re: How to capture screen output?
Hello Roland & fxm
I tried all the option, and it is indeed necessary to
CLOSE #CONSOLE
as otherwise the same value is returned indefinitely. As to WHILE-WEND loop Vs no loop, this is pretty indifferent as the execution time remains the same. I wonder why the examples include that loop.
If you are from an "Easter egg culture", enjoy the eggs!
R.
I tried all the option, and it is indeed necessary to
CLOSE #CONSOLE
as otherwise the same value is returned indefinitely. As to WHILE-WEND loop Vs no loop, this is pretty indifferent as the execution time remains the same. I wonder why the examples include that loop.
If you are from an "Easter egg culture", enjoy the eggs!
R.
Re: How to capture screen output?
Well, because it is the only truely 'safe way', to do it since,wergosum wrote:I wonder why the examples include that loop.
it has to 'work' independently of the amount of returned strings ...
Example: a 'dir' / 'ls' shell-statement (amount of return is considered: 'unknown')
Re: How to capture screen output?
Thanks, MrSwiss
Another related question
Is there any specific reason why the example that Roland pointed me to uses constants?
#IFDEF __FB_UNIX__
CONST TEST_COMMAND = "ls *"
#ELSE
CONST TEST_COMMAND = "dir *.*"
#ENDIF
[etc]
OPEN PIPE TEST_COMMAND FOR INPUT AS #nr
The command works fine with a string variable too.
R
Another related question
Is there any specific reason why the example that Roland pointed me to uses constants?
#IFDEF __FB_UNIX__
CONST TEST_COMMAND = "ls *"
#ELSE
CONST TEST_COMMAND = "dir *.*"
#ENDIF
[etc]
OPEN PIPE TEST_COMMAND FOR INPUT AS #nr
The command works fine with a string variable too.
R
Re: How to capture screen output?
Constant(s) are by definition 'global', while 'ordinary' *variables, are not.
'global' = access, from procedures as well, as module level code
*Variable exception: 'Dim Shared', which is generally not recommended!
'global' = access, from procedures as well, as module level code
*Variable exception: 'Dim Shared', which is generally not recommended!
Re: How to capture screen output?
OK, thanks. This makes sense too if one wants to compile for windows or linux...