Browser ProcessStartInfo浏览器输出
我已经尝试了我能想到的一切,也尝试了我能想到的每一个代码示例,但我无法使用Process获得任何类型的输出。请在打开浏览器时启动。我试着只查看错误输出,并使用实际URL导出404个错误和标准输出,但没有任何效果。下面是一个最简单的例子-尽管每次浏览器启动时它也会失败Browser ProcessStartInfo浏览器输出,browser,process,processstartinfo,Browser,Process,Processstartinfo,我已经尝试了我能想到的一切,也尝试了我能想到的每一个代码示例,但我无法使用Process获得任何类型的输出。请在打开浏览器时启动。我试着只查看错误输出,并使用实际URL导出404个错误和标准输出,但没有任何效果。下面是一个最简单的例子-尽管每次浏览器启动时它也会失败 //Default Browser RegistryKey key = null; string defaultPath = ""; try {
//Default Browser
RegistryKey key = null;
string defaultPath = "";
try
{
key = Registry.ClassesRoot.OpenSubKey("HTTP\\shell\\open\\command", false);
defaultPath = key.GetValue("").ToString().ToLower().Replace("\"", "");
if (!defaultPath.EndsWith(".exe"))
defaultPath = defaultPath.Substring(0, defaultPath.LastIndexOf(".exe") + 4);
}
catch { }
finally
{
if (key != null)
key.Close();
}
无工作代码:
ProcessStartInfo browserInfo = new ProcessStartInfo();
browserInfo.CreateNoWindow = true;
browserInfo.WindowStyle = ProcessWindowStyle.Hidden;
browserInfo.FileName = defaultPath;
browserInfo.Arguments = "http://www.google.com";
browserInfo.UseShellExecute = false;
browserInfo.RedirectStandardError = true;
browserInfo.RedirectStandardOutput = true;
string error = "";
string output = "";
String strProcessResults;
try
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = defaultPath;
p.StartInfo.Arguments = "http://www.google.com/NoneYa.html";
p.Start();
// Read the output stream first and then wait.
strProcessResults = p.StandardError.ReadToEnd();
p.WaitForExit();
}
catch (System.ComponentModel.Win32Exception BrowserX)
{
//We ignore the error if a browser does not exist!
if (BrowserX.ErrorCode != -2147467259)
throw BrowserX;
}
或
我从未真正检查过,但如果你的浏览器将任何内容打印到stdout,我会感到惊讶。这是一个窗口应用程序。原来是这样的,我最后写了一个C++的内核监视器,它拦截了调用并将它们分开打印出来。
try
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = defaultPath;
p.StartInfo.Arguments = "http://www.google.com";
p.Start();
// Read the output stream first and then wait.
strProcessResults = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch (System.ComponentModel.Win32Exception BrowserX)
{
//We ignore the error if a browser does not exist!
if (BrowserX.ErrorCode != -2147467259)
throw BrowserX;
}