【问题标题】:Cannot run Graphviz from C# as new process无法从 C# 将 Graphviz 作为新进程运行
【发布时间】:2016-10-03 16:54:24
【问题描述】:

我在 GraphViz 的 bin 文件夹中创建了一个 .dot 文件。

如果我从命令行执行:dot -Tpng -o graph.png -graph.dot 它会创建一个 png 图像,但如果我在 C# 中运行它,则不会创建 png 文件。该程序以管理员身份运行。 (检查下面的代码)

using (var dot = new Process())
{
    dot.StartInfo.Verb = "runas"; // Run process as admin.
    dot.StartInfo.FileName = @"C:\Program Files (x86)\Graphviz2.38\bin\dot.exe";
    dot.StartInfo.Arguments = "-Tpng -o graph.png -graph.dot";
    dot.Start();
    dot.WaitForExit();
}

【问题讨论】:

  • .dot 文件不能以“-”开头
  • 您可能还想设置WorkingDirectory
  • @AxelKemper 我删除了“-”/仍然没有运行。
  • @ChrisK 我设置了目录。像这样:dot.StartInfo.WorkingDirectory=@"C:\Program Files (x86)\Graphviz2.38\bin\";仍然没有创建我的图片。

标签: c# process png graphviz


【解决方案1】:

从 cmd 运行,将 /C 添加到参数的开头

using (var dot = new Process())
{
    dot.StartInfo.Verb = "runas"; // Run process as admin.
    dot.StartInfo.FileName = "cmd.exe";
    dot.StartInfo.Arguments = "/C dot -Tpng -o graph.png -graph.dot";
    dot.Start();
    dot.WaitForExit();
}

【讨论】:

    【解决方案2】:

    您没有设置工作目录,因此该文件可能已生成但位于 windows32 或类似的默认位置。

    试试下面的

    using (var dot = new Process())
    {
        dot.StartInfo.Verb = "runas"; // Run process as admin.
        dot.StartInfo.FileName = @"C:\Program Files (x86)\Graphviz2.38\bin\dot.exe";
        dot.StartInfo.WorkingDirectory = @"C:\ProgramData"; # or some other location you can write to
        dot.StartInfo.Arguments = "-Tpng -o graph.png -graph.dot";
        dot.Start();
        dot.WaitForExit();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2014-11-19
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      • 2014-04-01
      相关资源
      最近更新 更多