使用 c 文件中的命令行

发布于 2025-01-15 14:41:11 字数 3225 浏览 3 评论 0原文

这段代码是解析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&#45;&gt;b -->
<g id="edge1" class="edge"><title>c&#45;&gt;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2025-01-22 14:41:12

这是 dot 命令的输出,除非另有指示输出到 stdout。也许您打算将输出保存到文件中?

char chProgramVar[] = "echo 'digraph { c -> b }' | dot -Tsvg -o output.svg" ;

然后可以在浏览器或 SVG 查看器中打开生成的文件 output.svg。当然,您可以添加代码以使用浏览器或查看器在代码本身中打开 SVG。

That is the output of the dot command which unless otherwise directed outputs to stdout. Perhaps you intended to save the output to a file?

char chProgramVar[] = "echo 'digraph { c -> b }' | dot -Tsvg -o output.svg" ;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文