ReadString
ReadString["file"]
reads the complete contents of a file and returns it as a string.
ReadString[stream]
reads everything from a stream and returns it as a string.
ReadString[proc]
reads everything generated by an external process and returns it as a string.
ReadString[src,term]
reads until the terminator term is encountered.
Details and Options
- ReadString[File["file"],…] is also supported.
- ReadString["file",…] and ReadString[File["file",…] will first open "file" for reading if it is not already open. The file will be left open unless the default terminator, EndOfFile, is used.
- ReadString["file",…] and ReadString[File["file",…] open "file" using OpenRead with BinaryFormatTrue.
- 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 TimeConstraint->t, ReadString waits at most t seconds, then returns whatever it has read by that time.
- The terminator term can be any of the following:
-
"string" literal string patt string pattern EndOfBuffer end of the buffer of available content EndOfFile end of the source of content (default) - ReadString[src] or ReadString[src,EndOfFile] reads until a stream has ended or the external process providing input has terminated.
- If ReadString is called on a source of content that has already been exhausted, it returns EndOfFile.
- ReadString[src,EndOfBuffer] does not block and returns whatever is already available in the input buffer.
Examples
open allclose allBasic Examples (2)
Scope (5)
Read the first paragraph of a File object:
Start the system shell process:
Write two commands into the system shell process, then exit it:
Return the full shell process output once it has finished running:
Start the system shell process:
Write some commands into the shell process:
Read the shell process output right until the terminator is found:
Start the system shell process:
Write some commands into the shell process:
Read the process output until a given string pattern is found:
Start the system shell process:
Start the Wolfram Language from the shell:
Read the Wolfram Language output:
Text
Wolfram Research (2014), ReadString, Wolfram Language function, https://reference.wolfram.com/language/ref/ReadString.html (updated 2016).
CMS
Wolfram Language. 2014. "ReadString." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/ReadString.html.
APA
Wolfram Language. (2014). ReadString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReadString.html