GET_STDIN doesn't work with curl
Dec 16, 2020 7:41:12 GMT 1
Post by rikky on Dec 16, 2020 7:41:12 GMT 1
Hello,
Thanks for the LOAD$ solution.
I cannot do this in the original post, for the troubleshooting area is currently occupied.
Nowadays the internet is full of API's, and they spit there information out on JSON strings.
So I want to pipe this information through a UNJSON.bac program to get a more human readable thing.
I have this program:
Well, I use this program a lot.
Everywere in fact, and it always works.
gives hallo, you guessed it.
Also the output of other BaCon programmes can be piped through GET_STDIN without problems.
But now this one:
response:
next:
response:
okee:
response:
This is all very good.
The problem arises when I curl my website from out of another BaCon program
PING.bac:
response:
And now the cherry on the cake:
response:
Nothing.
Whatever I try.
Saving the response to a file and then load the file again and print it, or even print something completely different, the result is nothing.
However, the next thing works:
But this doesn't:
Rik.
Edit: deleted a double RETURN string$
Thanks for the LOAD$ solution.
I cannot do this in the original post, for the troubleshooting area is currently occupied.
Nowadays the internet is full of API's, and they spit there information out on JSON strings.
So I want to pipe this information through a UNJSON.bac program to get a more human readable thing.
I have this program:
FUNCTION GET_STDIN$()
LOCAL string$ TYPE STRING
LOCAL stndin
WHILE TRUE
stndin = WAIT(STDIN_FILENO, 50)
IF stndin = 0 THEN BREAK
string$ = string$ & CHR$(stndin)
WEND
IF string$ <> "" THEN string$ = RIP$(string$,-1)
RETURN string$
END FUNCTION
PRINT GET_STDIN$()
Well, I use this program a lot.
Everywere in fact, and it always works.
echo "hallo" | GET_STDIN
gives hallo, you guessed it.
Also the output of other BaCon programmes can be piped through GET_STDIN without problems.
But now this one:
curl --silent -X GET https://api.coingecko.com/api/v3/ping
response:
{"gecko_says":"(V3) To the Moon!"}
next:
curl --silent -X GET https://api.coingecko.com/api/v3/ping | ./GET_STDIN
response:
(23) Failed writing body
okee:
curl --silent -X GET https://api.coingecko.com/api/v3/ping;echo | ./GET_STDIN
response:
{"gecko_says":"(V3) To the Moon!"}
This is all very good.
The problem arises when I curl my website from out of another BaCon program
PING.bac:
PRINT CHOP$(EXEC$("curl --silent -X GET https://api.coingecko.com/api/v3/ping;echo"))
response:
{"gecko_says":"(V3) To the Moon!"}
And now the cherry on the cake:
./PING | ./GET_STDIN
response:
Nothing.
Whatever I try.
Saving the response to a file and then load the file again and print it, or even print something completely different, the result is nothing.
However, the next thing works:
./PING | cat
But this doesn't:
./PING | cat | ./GET_STDIN
Rik.
Edit: deleted a double RETURN string$