({{, (RefLink[ReadLine, paclet:ref/ReadLine])["file"]
reads a line of text from a file and returns it as a string.}, {, (RefLink[ReadLine, paclet:ref/ReadLine])[stream]
reads a line of text from a stream and returns it as a string.}, {, (RefLink[ReadLine, paclet:ref/ReadLine])[proc]
reads a line of text generated by an external process and returns it as a string.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ReadLine, paclet:ref/ReadLine]) reads until it encounters a newline, either "\n" or "\r\n".

(RefLink[ReadLine, paclet:ref/ReadLine])[(RefLink[File, paclet:ref/File])["file"],…] is also supported.

(RefLink[ReadLine, paclet:ref/ReadLine])["file",…] and (RefLink[ReadLine, paclet:ref/ReadLine])[(RefLink[File, paclet:ref/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 (RefLink[Close, paclet:ref/Close]).

(RefLink[ReadLine, paclet:ref/ReadLine]) is a blocking function that by default will not return until it has read a complete line of text.

With the option setting (RefLink[TimeConstraint, paclet:ref/TimeConstraint])->t, (RefLink[ReadLine, paclet:ref/ReadLine]) waits at most t seconds, then returns whatever it has read by that time.

If (RefLink[ReadLine, paclet:ref/ReadLine]) is called on a source of content that has already been exhausted, it returns (RefLink[EndOfFile, paclet:ref/EndOfFile]).

(RefLink[ReadLine, paclet:ref/ReadLine])[src] is equivalent to (RefLink[ReadString, paclet:ref/ReadString])[src,"\n"|"\r\n"].

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Read the first line of the file "ExampleData/strings":

ReadLine["ExampleData/strings"]

Read the next line:

ReadLine["ExampleData/strings"]

Both outputs are strings:

Head/@{%,%%}

Close the file:

Close["ExampleData/strings"]

Start the system shell process:

process=StartProcess[$SystemShell]

Read all initial output; depending on the operating system and shell, this can result in an empty string:

ReadString[process,EndOfBuffer];

Write a command into the shell:

WriteLine[process,"echo example"];

Read the command output:

ReadLine[process]

Start the system shell process:

process=StartProcess[$SystemShell]

Read all initial output; depending on the operating system and shell, this can result in an empty string:

ReadString[process,EndOfBuffer];

Write two "echo" commands in the shell, then close it with "exit":

BinaryWrite[process,"echo line 1
echo line 2
exit\n"];

Read the shell process output:

ReadLine[process]

ReadLine[process]

ReadLine[process]

OpenersExampleSection1(Spacer1)Scope  (1)

Read the first line of a (RefLink[File, paclet:ref/File]) object:

ReadLine[File["ExampleData/USConstitution.txt"]]

Close the file:

Close[File["ExampleData/USConstitution.txt"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[WriteLine, paclet:ref/WriteLine])  ▪  (RefLink[ReadString, paclet:ref/ReadString])  ▪  (RefLink[ReadList, paclet:ref/ReadList])  ▪  (RefLink[Read, paclet:ref/Read])  ▪  (RefLink[Import, paclet:ref/Import])  ▪  (RefLink[BinaryRead, paclet:ref/BinaryRead])  ▪  (RefLink[DeviceRead, paclet:ref/DeviceRead])  ▪  (RefLink[ProcessObject, paclet:ref/ProcessObject])  ▪  (RefLink[InputStream, paclet:ref/InputStream])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Files, paclet:guide/Files])}, {▪(RefLinkPlain[Low-Level File Operations, paclet:guide/LowLevelFileOperations])}, {▪(RefLinkPlain[Direct Control of External Processes, paclet:guide/DirectControlOfExternalProcesses])}})}})