以前はwkhtmltopdfを正常に使用していましたが、プロセスを開始するときに特定のアカウントを使用する必要があるというシナリオがあります。有効なユーザー名/pwdを設定すると、標準出力ストリームは空になり、戻りコードは-1になります。username / pwdをコメントアウトするとすぐに、期待どおりに機能します。
これを.Net4、Win764ビットでテストします。
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、Password、Domainをコメントアウトすると、出力にデータが含まれます。そうでない場合、資格情報を使用しようとすると、出力が空白になり、returnCodeが-1になります。
他の人がこれに遭遇したことを願って、一般的なシナリオのように思えます、確かに単純な何かを見逃しています...
助けてくれてありがとう!