如何使用C#更改Pandoc中的目录?

时间:2018-06-05 15:08:58

标签: c# markdown pandoc epub

如何设置目录并使用C#在Pandoc 中执行文件转换

        string processName = "pandoc.exe";          
        string arguments = @"cd C/Users/a/Desktop/ConvertFileApp/ConvertFileApp/bin/Debug/marcdovd "
                          + "chapter1.markdown "
                          + "chapter2.markdown "
                          + "chapter3.markdown "
                          + "title.txt "
                          + "-o progit.epub";

        var psi = new ProcessStartInfo
        {
            FileName = processName,
            Arguments = arguments,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardInput = true
        };

        var process = new Process { StartInfo = psi };
        process.Start();

此代码不起作用。

1 个答案:

答案 0 :(得分:0)

您使用cd命令作为参数调用可执行文件。这相当于在命令行上运行以下命令:

pandoc.exe cd C/Users/a/Desktop/ConvertFileApp/ConvertFileApp/bin/Debug/marcdovd chapter1.markdown chapter2.markdown chapter3.markdown title.txt -o progit.epub

虽然我不熟悉Pandoc,但我想你实际上想要做这样的事情:

cd C:/Users/a/Desktop/ConvertFileApp/ConvertFileApp/bin/Debug/marcdovd
pandoc.exe chapter1.markdown chapter2.markdown chapter3.markdown title.txt -o progit.epub

要执行此操作,请从参数中删除cd命令并设置the ProcessStartInfo.WorkingDirectory property,如下所示:

    string processName = "pandoc.exe";          
    string arguments = "chapter1.markdown "
                      + "chapter2.markdown "
                      + "chapter3.markdown "
                      + "title.txt "
                      + "-o progit.epub";

    var psi = new ProcessStartInfo
    {
        FileName = processName,
        Arguments = arguments,
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardInput = true,
        WorkingDirectory = @"C:/Users/a/Desktop/ConvertFileApp/ConvertFileApp/bin/Debug/marcdovd"
    };

    var process = new Process { StartInfo = psi };
    process.Start();