[Implemented] read STDIN, STDERR from PB

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

[Implemented] read STDIN, STDERR from PB

Post by naw »

Hi Fred,

Please, Please, Please can we have a PB standard way of reading STDIN & STDOUT output from an external command.... in PB3.7 (so that when you get around to updating the Linux version we get it there too!!)

I've seen that there are vaious Windows API methods, but no obvious way of doing the same on Linux.

This is quite a core function, so would be best implemented as *part* of PB.

Thanks ... Nigel

(Implemented with ReadProgramString(), ReadProgramError() and WriteProgramStrin())
Ta - N
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I would really love to see this too :)

Dunno how it would be implemented though, for example once the 'pipe' is open (to StdOut say...) you need some way of continuously being able to read the data from the program/script because not all output comes at once, especially if the program is performing long calculations before it sends stuff to StdOut.

Tricky! C'mon Fred do us proud ;)
--Kale

Image
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

This would be a VERY awsome feature! :!: PLEASE
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

Hi, why not just implement it as:

PB_STDIN$ and PB_STDERR$ for short inputs

and like this for big data:

openFile(#PB_STDIN,"") -or-
openFile(#PB_STDERR,"")

and just normal PB commands for reading the data:

openFile(#PB_STDIN, "")
xyz=ReadByte() -or-
xyz$=ReadString() -or-
xyz.f=ReadFloat() -etc-
closeFile(#PB_STDIN, "")
Ta - N
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

and just normal PB commands for reading the data:

openFile(#PB_STDIN, "")
xyz=ReadByte() -or-
xyz$=ReadString() -or-
xyz.f=ReadFloat() -etc-
closeFile(#PB_STDIN, "")
Yeah but these would have to be looped continuously in order to catch data at a later stage!
--Kale

Image
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

ok - how about:

openFile(#PB_STDIN, "")
Repeat:
_stdin$=_stdin$+chr(13)+ReadString()
Until Eof(#PB_STDIN)
closeFile(#PB_STDIN, "")

or:

openFile(#PB_STDERR, "")
Repeat:
_stderr$=_stderr$+chr(13)+ReadString()
Until Eof(#PB_STDERR)
closeFile(#PB_STDERR, "")

- not forgetting:

openFile(#PB_STDOUT, "")
writeStringN("Error 1234 - This function does not exist yet...")
closeFile(#PB_STDOUT, "")
Ta - N
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

> ... why not just implement it as:
> PB_STDIN$ and PB_STDERR$ for short inputs

and what about PB_STDOUT$ for output that can be redirected by the user (command line, batch) ??
Horst.
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Post by Thade »

Hmm - In 25 years of programming I didn't have any ravenous hunger for those - Is that the future of Windows? Commandline Input Output Errorchecking?
:wink: Honest - make a deaf, dumb and blind guy happy - what is it good for?
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Honest - make a deaf, dumb and blind guy happy - what is it good for?
In my case writing nice GUI's for new/old command line utils/programs

P.S. Better to have and not need, than to need and not have! :wink:
--Kale

Image
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Kale wrote: P.S. Better to have and not need, than to need and not have! :wink:
Exactly. I would love this. Man they have these features in java and they are very slick to use.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

Guys, this was a request for Linux - not for Windows (there >1 OS in the world y'know ;-)

In the Unix world, utils usually consist of a command line processor and an optional / seperate Graphical Front End. This makes STDIN/OUT/ERR a simple but also very powerful and flexible means of passing complex / large amounts of data for further processing.

There's also no issue of "How do I pass *this* message to *that* application " and changing API specs - it just works transparently...
Ta - N
Post Reply