Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

file operations: What Are Multichannel File Descriptors?

SystemVerilog Testbench Components

Runnable example from the SystemVerilog file operations tutorial (What Are Multichannel File Descriptors?)

Open in IDE
testbench.sv
module tb;
  integer fd1, fd2, both;

  initial begin
    fd1 = $fopen ("file1.txt", "w");
    fd2 = $fopen ("file2.txt", "w");

    // Combine both descriptors into one - a single $fdisplay call
    // now writes the same line to both files at once
    both = fd1 | fd2;
    $fdisplay (both, "This goes to both files");

    $fclose(fd1);
    $fclose(fd2);
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.