使用 c 文件中的命令行
这段代码是解析verilog文件,当它找到字符“m”时,访问命令行并运行一个简单的点程序。然而,我不断收到一个奇怪的错误,它打印出一堆 html 代码。
#include "mycode.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE* fPointer;
fPointer = fopen("test.v","r");
char singleLine[150];//printing out the verilog file line by line
//char* cArray[5];
char chProgramVar[] = "echo 'digraph { c -> b }' | dot -Tsvg ";
while(!feof(fPointer)){//file end of file, wait till you get an end of file
fgets(singleLine,150,fPointer);//gets one line
for(int i=0;i<strlen(singleLine);i++){
if (singleLine[i] == 'm'){
setenv("ShellVar", chProgramVar, 1) ;
system("echo $ShellVar") ;
}
}
puts(singleLine);
}
fclose(fPointer);
return 0;
}
这是我得到的输出
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- c -->
<g id="node1" class="node"><title>c</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00">c</text>
</g>
<!-- b -->
<g id="node2" class="node"><title>b</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times,serif" font-size="14.00">b</text>
</g>
<!-- c->b -->
<g id="edge1" class="edge"><title>c->b</title>
<path fill="none" stroke="black" d="M27,-71.6966C27,-63.9827 27,-54.7125 27,-46.1124"/>
<polygon fill="black" stroke="black" points="30.5001,-46.1043 27,-36.1043 23.5001,-46.1044 30.5001,-46.1043"/>
</g>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- c -->
,还有更多,但这是一个很长的输出。
This code is to parse through a verilog file, and when it finds the character 'm', access the command line and run a simple dot program. However I keep getting a weird error where it prints out a bunch of html code.
#include "mycode.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE* fPointer;
fPointer = fopen("test.v","r");
char singleLine[150];//printing out the verilog file line by line
//char* cArray[5];
char chProgramVar[] = "echo 'digraph { c -> b }' | dot -Tsvg ";
while(!feof(fPointer)){//file end of file, wait till you get an end of file
fgets(singleLine,150,fPointer);//gets one line
for(int i=0;i<strlen(singleLine);i++){
if (singleLine[i] == 'm'){
setenv("ShellVar", chProgramVar, 1) ;
system("echo $ShellVar") ;
}
}
puts(singleLine);
}
fclose(fPointer);
return 0;
}
this is the output i get
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- c -->
<g id="node1" class="node"><title>c</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00">c</text>
</g>
<!-- b -->
<g id="node2" class="node"><title>b</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times,serif" font-size="14.00">b</text>
</g>
<!-- c->b -->
<g id="edge1" class="edge"><title>c->b</title>
<path fill="none" stroke="black" d="M27,-71.6966C27,-63.9827 27,-54.7125 27,-46.1124"/>
<polygon fill="black" stroke="black" points="30.5001,-46.1043 27,-36.1043 23.5001,-46.1044 30.5001,-46.1043"/>
</g>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- c -->
there's more, but it was a very long output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是
dot
命令的输出,除非另有指示输出到stdout
。也许您打算将输出保存到文件中?然后可以在浏览器或 SVG 查看器中打开生成的文件 output.svg。当然,您可以添加代码以使用浏览器或查看器在代码本身中打开 SVG。
That is the output of the
dot
command which unless otherwise directed outputs tostdout
. Perhaps you intended to save the output to a file?The resulting file output.svg can then be opened in a browser or SVG viewer. You could of course add code to open the SVG in the code itself using a browser or viewer.