ReadLine
ReadLine["file"]
reads a line of text from a file and returns it as a string.
ReadLine[stream]
reads a line of text from a stream and returns it as a string.
ReadLine[proc]
reads a line of text generated by an external process and returns it as a string.
Details and Options
- ReadLine reads until it encounters a newline, either "\n" or "\r\n".
- ReadLine[File["file"],…] is also supported.
- ReadLine["file",…] and ReadLine[File["file"],…] will first open "file" for reading if it is not already open. The file will be left open until it is closed by a call to Close.
- ReadLine["file",…] and ReadLine[File["file"],…] open "file" using OpenRead with BinaryFormatTrue.
- ReadLine is a blocking function that by default will not return until it has read a complete line of text.
- With the option setting TimeConstraint->t, ReadLine waits at most t seconds, then returns whatever it has read by that time.
- If ReadLine is called on a source of content that has already been exhausted, it returns EndOfFile.
- ReadLine[src] is equivalent to ReadString[src,"\n" "\r\n"].
Examples
open allclose allBasic Examples (3)
Read the first line of the file "ExampleData/strings":
Start the system shell process:
Read all initial output; depending on the operating system and shell, this can result in an empty string:
Write a command into the shell:
Start the system shell process:
Read all initial output; depending on the operating system and shell, this can result in an empty string:
Write two "echo" commands in the shell, then close it with "exit":
Scope (1)
Read the first line of a File object:
Text
Wolfram Research (2014), ReadLine, Wolfram Language function, https://reference.wolfram.com/language/ref/ReadLine.html (updated 2016).
CMS
Wolfram Language. 2014. "ReadLine." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/ReadLine.html.
APA
Wolfram Language. (2014). ReadLine. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReadLine.html