Вывод браузера ProcessStartInfo

Я перепробовал все, что мог придумать, и все мыслимые образцы кода, но не могу получить какой-либо вывод с помощью Process.Start при открытии браузера. Я пробовал просто смотреть на вывод ошибок и выявлять ошибки 404 и стандартный вывод, используя фактические URL-адреса - ничего не работает. Вот самый простой пример - хотя он тоже не работает, хотя браузер каждый раз запускается...

        //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;
        }

OR

        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;
        }

person Ken Tola    schedule 24.01.2011    source источник


Ответы (1)


На самом деле я никогда не проверял, но я был бы удивлен, если бы ваш браузер вывел что-нибудь на стандартный вывод. Это оконное приложение.

person Marcelo Cantos    schedule 24.01.2011
comment
Так оно и есть — в итоге я написал монитор ядра на C++, который перехватывал вызовы и распечатывал их отдельно. - person Ken Tola; 23.04.2012