如何设置目录并使用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();
此代码不起作用。
答案 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();