fdio

fdio([name::AbstractString, ]fd::Integer[, own::Bool]) -> IOStream

Create an IOStream object from an integer file descriptor. If own is true, closing this object will close the underlying descriptor. By default, an IOStream is closed when it is garbage collected. name allows you to associate the descriptor with a named file.

Examples

# Create an IOStream object from a file descriptor
fdio(fd::Integer) -> IOStream

julia> io = fdio(3)
IOStream(<file descriptor 3>)

julia> println(io, "Hello, Julia!")
Hello, Julia!

This example creates an IOStream object io using the file descriptor 3. The IOStream can be used to perform I/O operations on the associated file or device.

# Create an IOStream object from a file descriptor with ownership control
fdio(name::AbstractString, fd::Integer, own::Bool) -> IOStream

julia> io = fdio("/path/to/file.txt", 4, true)
IOStream(<file descriptor 4>)

julia> write(io, "Some data")
9

julia> close(io)  # Closes the underlying file descriptor

julia> io = fdio("/path/to/another_file.txt", 5, false)
IOStream(<file descriptor 5>)

julia> read(io, String)
"Some data"

In this example, fdio creates an IOStream object io using the file descriptor 4 and associates it with the file path /path/to/file.txt. The own argument is set to true, indicating that closing the IOStream will also close the underlying file descriptor.

If own is set to false, the IOStream is created without ownership control, allowing the file descriptor to remain open even after the IOStream is closed.

Note: The name argument is optional and can be omitted if you don't need to associate a file path with the file descriptor.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: