我以前成功地使用過wkhtmltopdf,但現在我有一個場景,我需要在啓動過程時使用特定的帳戶。當我設置一個有效的用戶名/密碼時,標準輸出流爲空,返回碼爲-1。只要我註釋掉用戶名/密碼,它就會按預期工作。用ProcessInfo用戶名和密碼調用wkhtmltopdf時無法讀取StandardOutput
在.Net 4,Win 7 64位測試。
class Program
{
static void Main(string[] args)
{
var wkhtmlDir = AppDomain.CurrentDomain.BaseDirectory;
var wkhtml = wkhtmlDir + @"\wkhtmltopdf.exe";
var info = new ProcessStartInfo(wkhtml);
info.CreateNoWindow = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.WorkingDirectory = wkhtmlDir;
info.Arguments = "http://www.google.com -";
var securePassword = new SecureString();
var password = "mypassword";
foreach (var c in password)
{
securePassword.AppendChar(c);
}
//comment out next three lines, and it works!
info.UserName = "myuser";
info.Password = securePassword;
info.Domain = "mydomain";
using (var process = Process.Start(info))
{
var output = process.StandardOutput.ReadToEnd();
// wait or exit
process.WaitForExit(60000);
var returnCode = process.ExitCode;
}
}
如果我註釋掉info.UserName,密碼,域,輸出有數據,否則的話我試着使用的憑證,輸出爲空白,RETURNCODE爲-1。
希望能有其他人進入這個運行,似乎是一個常見的情況,我肯定失去了一些東西簡單...
感謝您的幫助!