STATIC PROPERTY READ In AS FileReturns the standard input stream.
This example demonstrates how to read and write to standard input, output and error. It demonstrates the use of File.In, File.Out and File.Err. Each line seen on standard input is echoed back first on standard output and then on standard error.
PUBLIC SUB Main() DIM inputLine AS String ' Loop until the end of the standard input file stream WHILE NOT Eof(File.In) ' Read a line from standard input. This is the same as: ' LINE INPUT inputLine LINE INPUT #File.In, inputLine ' Print to standard output. This is the same as: ' PRINT inputLine PRINT #File.Out, inputLine ' Print to standard error PRINT #File.Err, inputLine WEND END
Create a Command-line application and place the above code in the startup module. If you run this example in the Gambas IDE the application will appear to hang. If you enter some text in the IDE console window each line will be echoed back to you twice. But as the application never sees the end of file for the standard input stream you will need to stop the project.
The get a better idea of what the example is doing create a executable from your project. Suppose we call this executable pipe.gambas. Now open a Linux terminal and cd to the directory where you saved the executable. If you enter the command:
ls -a | ./pipe.gambasyou will see each line from the ls -a command echoed to you twice. Once from the standard input and once from standard error. This time this application will see the end of file from the standard input stream and so ends correctly. Now try:
ls -a | ./pipe.gambas > files.txthere we redirect the standard input stream to a file and you will see the standard error output stream in the terminal window. You should now have a file in the directory with the output of the ls -a command.