redirect_stdin
redirect_stdin([stream])
Like redirect_stdout, but for STDIN. Note that the order of the return tuple is still (rd,wr), i.e. data to be read from STDIN, may be written to wr.
Examples
-
Redirect STDIN to a file:
julia> file = open("input.txt", "w"); julia> redirect_stdin(file);
This example redirects the STDIN stream to a file named "input.txt". All subsequent input read from STDIN will be read from this file.
-
Restore STDIN after redirection:
julia> original_stdin = redirect_stdin();
This example restores the STDIN stream to its original source after redirection. The
redirect_stdin()
function without an argument returns the original STDIN stream.
Common mistake example:
julia> redirect_stdin(10)
ERROR: MethodError: no method matching redirect_stdin(::Int64)
In this example, a non-stream argument is provided to redirect_stdin()
. The function expects a stream object to redirect STDIN, not an integer or any other type. Make sure to provide a valid stream object as an argument to redirect_stdin()
.
See Also
deserialize, eachline, eof, fd, flush, IOBuffer, ismarked, isopen, isreadonly, mark, nb_available, open, pipeline, position, read, read!, readavailable, readbytes, readbytes!, readline, redirect_stderr, redirect_stdin, reset, seek, seekend, seekstart, serialize, skip, skipchars, TextDisplay, unmark, write, writemime,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.