System verilog 如何在SystemVerilog中存储$system(“…”)调用的返回值?
如果我模拟以下模块:System verilog 如何在SystemVerilog中存储$system(“…”)调用的返回值?,system-verilog,System Verilog,如果我模拟以下模块: module test; longint seconds; initial begin seconds = $system("date +%s"); $display("Seconds: %0d", seconds); $finish; end endmodule ncsim和vsim的输出均为: 1571172006 Seconds: 0 因此我可以看到,$system调用正在以秒为单位打印时
module test;
longint seconds;
initial begin
seconds = $system("date +%s");
$display("Seconds: %0d", seconds);
$finish;
end
endmodule
ncsim
和vsim
的输出均为:
1571172006
Seconds: 0
因此我可以看到,$system
调用正在以秒为单位打印时间1571172006
,但是变量seconds
的值为0
,因此我不保存该值
我有办法保存这个值吗?(最好不使用DPI)
提前谢谢
这很可怕,但您可以将linux命令的输出通过管道传输到一个文件中,然后读取该文件:
$system("date +%s | tee date.txt");
fd = $fopen("date.txt","r");
count=($fgets(s, fd) == 0); assert(count == 0);
count=($sscanf(s,"%d", seconds)); assert(count == 1);
$display("Seconds: %0d", seconds);
我不知道您为什么不想使用DPI。比马修的方法简单得多。投票赞成一个解决方案!如果有更干净的解决方案,我会把这个问题留待讨论,但我非常感谢你的回答。我在
count!=0
不过--我不知道为什么。@CharlesClayton在这里修好了,但不是在EDA操场上,因为我晚上关掉了笔记本电脑。“最后一分钟编辑的诅咒”。@CharlesClayton也修复了EDA游乐场。您不想存储返回值。您希望捕获命令打印到标准输出的内容。返回值(即退出代码)将为0
,以指示命令成功。
module test;
longint seconds;
initial begin
int fd;
int count;
string s;
$system("date +%s | tee date.txt");
fd = $fopen("date.txt","r");
count=($fgets(s, fd) == 0); assert(count == 0);
count=($sscanf(s,"%d", seconds)); assert(count == 1);
$display("Seconds: %0d", seconds);
$finish;
end
endmodule