({{, (RefLink[ReadString, paclet:ref/ReadString])["file"]
reads the complete contents of a file and returns it as a string.}, {, (RefLink[ReadString, paclet:ref/ReadString])[stream] 
reads everything from a stream and returns it as a string.}, {, (RefLink[ReadString, paclet:ref/ReadString])[proc]
reads everything generated by an external process and returns it as a string.}, {, (RefLink[ReadString, paclet:ref/ReadString])[src,term]
reads until the terminator term is encountered.}})

OpenersNotesSection(Spacer1)Details and Options

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

(RefLink[ReadString, paclet:ref/ReadString])["file",…] and (RefLink[ReadString, paclet:ref/ReadString])[(RefLink[File, paclet:ref/File])["file",…] will first open "file" for reading if it is not already open. The file will be left open unless the default terminator, (RefLink[EndOfFile, paclet:ref/EndOfFile]), is used.

(RefLink[ReadString, paclet:ref/ReadString]) is a blocking function that by default will not return until it has read whatever it is specified to read.

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

The terminator term can be any of the following:

(RefLink[ReadString, paclet:ref/ReadString])[src] or (RefLink[ReadString, paclet:ref/ReadString])[src,(RefLink[EndOfFile, paclet:ref/EndOfFile])] reads until a stream has ended or the external process providing input has terminated.

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

(RefLink[ReadString, paclet:ref/ReadString])[src,(RefLink[EndOfBuffer, paclet:ref/EndOfBuffer])] does not block and returns whatever is already available in the input buffer.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Read a complete file into a string:

ReadString["ExampleData/strings"]

Head[%]

Start the system shell process:

process=StartProcess[$SystemShell]

Write two commands into the system shell process:

WriteLine[process,"echo line 1"];

WriteLine[process,"echo line 2"];

Read the system shell output without blocking:

ReadString[process,EndOfBuffer]

OpenersExampleSection1(Spacer1)Scope  (5)

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

ReadString[File["ExampleData/USConstitution.txt"], "\n\n"]

Start the system shell process:

process=StartProcess[$SystemShell]

Write two commands into the system shell process, then exit it:

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

Return the full shell process output once it has finished running:

ReadString[process]

Start the system shell process:

process=StartProcess[$SystemShell]

Write some commands into the shell process:

BinaryWrite[process,"echo before terminator:: after terminator
echo another line
exit\n"];

Read the shell process output right until the terminator is found:

ReadString[process,"::"]

Start the system shell process:

process=StartProcess[$SystemShell]

Write some commands into the shell process:

BinaryWrite[process,"echo line 1{some terminator}
echo line 2
exit\n"];

Read the process output until a given string pattern is found:

ReadString[process,"{"~~___~~"}"]

Start the system shell process:

process=StartProcess[$SystemShell]

Start the Wolfram Language from the shell:

WriteLine[process,First@$CommandLine];

Read the Wolfram Language output:

ReadString[process,EndOfBuffer]

Enter a computation to perform:

WriteLine[process, "2+2"];

Quit the kernel:

WriteLine[process, "Exit"];

Quit the system shell:

WriteLine[process, "exit"];

Read all remaining output into a string:

ReadString[process]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[WriteString, paclet:ref/WriteString])  ▪  (RefLink[ReadLine, paclet:ref/ReadLine])  ▪  (RefLink[ReadList, paclet:ref/ReadList])  ▪  (RefLink[Read, paclet:ref/Read])  ▪  (RefLink[ImportString, paclet:ref/ImportString])  ▪  (RefLink[ReadByteArray, paclet:ref/ReadByteArray])  ▪  (RefLink[BinaryRead, paclet:ref/BinaryRead])  ▪  (RefLink[DeviceRead, paclet:ref/DeviceRead])  ▪  (RefLink[ProcessObject, paclet:ref/ProcessObject])  ▪  (RefLink[InputStream, paclet:ref/InputStream])  ▪  (RefLink[Find, paclet:ref/Find])  ▪  (RefLink[LinkRead, paclet:ref/LinkRead])}})}})

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