console-application

Exception on decrypting file using BouncyCastle PGP

烂漫一生 提交于 2019-11-30 23:11:27
I was trying to decrypt this sample file given by the client, using a class called PgpDecrypt. But when the code comes to this line: Stream clear = pbe.GetDataStream(privKey); it returns an error: exception decrypting secret key Here's my decryption code: PgpDecrypt test = new PgpDecrypt(string.Concat(pathh, "TestDecryptionFile"), string.Concat(pathh, "mypgpprivatekey.key"), "mypassphrase", @"d:/test/", string.Concat(pathh, "clientpublickey.key")); FileStream fs = File.Open(string.Concat(pathh, "TestDecryptionFile"), FileMode.Open); test.Decrypt(fs, @"d:\test\"); I am using BouncyCastle as my

Centering text in C# console app only working with some input

梦想的初衷 提交于 2019-11-30 20:33:49
I am having a problem with centering text in a C#.NET4 console app. This is my method for centering the text: private static void centerText(String text) { int winWidth = (Console.WindowWidth / 2); Console.WriteLine(String.Format("{0,"+winWidth+"}", text)); } However, I just get the output as it would have been outputted normally. If I however use this line: Console.WriteLine(String.Format("{0,"+winWidth+"}", "text")); The "text" gets centered as it should. I am calling centerText with these two methods: private static void drawStars() { centerText("********************************************

Exit Code When Unhandled Exception Terminates Execution?

安稳与你 提交于 2019-11-30 19:29:50
When a C# .Net console application terminates due to an unhandled exception, are there rules determining which exit code is returned or is 255 always used? I haven't been able to find documentation on this. A simple console app that executes throw new Exception() dies with exit code 255. I'd like to know if it's safe to assume that all unhandled exceptions will return this same error code or if there are variations/corner cases I need to be aware of. C:\Temp\> ThrowsExceptionConsoleApp.exe C:\Temp\> echo %errorlevel% 255 Hans Passant No, not always. 255 is a Unix number, normally produced by

Why no text colors after using CreateFile(“CONOUT$” …) to redirect the console back to the active screen buffer?

隐身守侯 提交于 2019-11-30 19:08:54
问题 I had an old app based off of this setup (but more advanced): https://stackoverflow.com/a/33441726/1236397 Basically, it runs, processes stuff, and closes, and only opens a window if it needs to (runs via another application). Since porting this to Visual Studio 2017 on Windows 10 the output window failed to work. After a bit more investigation it appears the issue was related to the standard output being redirected for non -console applications (output type must be "Windows Application" to

How to execute child console programs without showing the console window from the Win32 GUI program?

吃可爱长大的小学妹 提交于 2019-11-30 18:46:34
(I've searched SO answers and found no clear solution to this problem.) I'm working on a MFC GUI program. This program runs various child programs including console program and shell command script(.cmd). Initially it displayed one GUI window and one console window (created with AllocConsole ) because there are many console output from the child processes. But many users complained about the console window so we decided to hide the console window. Firstly tried like below: if (AllocConsole()) { ::ShowWindow(::GetConsoleWindow(), SW_HIDE); } Okay, no console window but there are visible flicker

Unable to read data from the transport connection: The connection was closed error in console application

给你一囗甜甜゛ 提交于 2019-11-30 18:18:18
I have this code in console application and it runs in a loop try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search); request.Headers.Add("Accept-Language", "de-DE"); request.Method = "GET"; request.Accept = "text/html"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { string html = reader.ReadToEnd(); FindForMatch(html, url); } } } catch (Exception ex) { throw new Exception(ex.Message); } after few loops it gives Unable to read data from the transport

Getting WebBrowser Control To Work In Console Application?

依然范特西╮ 提交于 2019-11-30 18:08:46
I have a printer class that is capable of printing HTML via the WebBrowser object. I want to be able to print from a console application, but I get an error when my printer class tries to create a WebBrowser object: WebBrowser browser = new WebBrowser(); Error: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. I tried adding a reference to System.Windows.Forms into my console application but that didn't work. I don't have the slightest idea of what's going on here, but I would appreciate the help.

Clojure (read-line) doesn't wait for input

旧时模样 提交于 2019-11-30 17:14:10
问题 I am writing a text game in Clojure. I want the player to type lines at the console, and the game to respond on a line-by-line basis. Research showed me that (read-line) is the way one is meant to get text lines from standard input in Clojure, but it is not working for me. I am in a fresh Leiningen project, and I have added a :main clause to the project.clj pointing to the only source file: (ns textgame.core) (defn -main [& args] (println "Entering -main") ; (flush) ;makes no difference if

Get key from any process

删除回忆录丶 提交于 2019-11-30 16:26:52
Ive seen many solutions online but none does exactly what I want. What is the best/simplest way to get any keys pressed in a given process (not my console applicaton) while my application is running in background. I dont need the modifiers or anything. If you don't particularly care which process the keys are being pressed in the easiest method would be to call GetAsyncKeyState . It's rather limited though as it does not hook the keyboard and requires you to call it continuously. The best approach in my opinion is to hook the keyboard. Using SetWindowsHookEx you can actually explicitly specify

WebBrowser Control - Console Application - Events Not Firing

别等时光非礼了梦想. 提交于 2019-11-30 16:09:28
I have been navigating the various WebBrowser control stackoverflow questions , and I can't seem to find an answer to a problem I am having. I am trying to use the WebBrowser control to print a web page . Following MSDN's example , I have created the following console application: namespace WebPrintingMadness { using System; using System.Collections.Generic; using System.Text; /// <summary> /// The entry point of the program. /// </summary> class Program { /// <summary> /// The main entry point of the program. /// </summary> /// <param name="args">Program arguments.</param> [STAThread] public