console-application

Get base URL in Yii console application

ぐ巨炮叔叔 提交于 2019-12-08 17:35:47
问题 How to get base URL in a Yii CConsoleApplication application? I tried Yii::app()->request->getBaseUrl(true) and ended up with the following error. Undefined index: SERVER_NAME (/var/www/yii/framework/web/CHttpRequest.php:279) 回答1: There is no request object in a console application. the request object in a web application its an instance of CHttpRequest, if you are generating URLs in an offline task, you have to configure the baseUrl in some other way, perhaps in the configuration: "request"

Checking if any key pressed in console application C#

余生长醉 提交于 2019-12-08 17:09:27
问题 I need to check if any key is pressed in a console application. The key can be any key in the keyboard. Something like: if(keypressed) { //Cleanup the resources used } I had come up with this: ConsoleKeyInfo cki; cki=Console.ReadKey(); if(cki.Equals(cki)) Console.WriteLine("key pressed"); It works well with all keys except modifier keys - how can I check these keys? 回答1: This can help you: Console.WriteLine("Press any key to stop"); do { while (! Console.KeyAvailable) { // Do something } }

The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments

混江龙づ霸主 提交于 2019-12-08 15:30:14
问题 I am using .NET Core dependency injection, but when I am trying to get the service in another class, I am getting the 'IServiceProvider.GetService(Type)' cannot be used with type arguments' error. What does this error means? I understand that a generic type argument is something like this: GenericInterface<>, and the GetService method does not take the GenericInterface<> as an argument. Why am I getting this error and how do I solve it? The interface public interface IService { void Process()

How restart the Console app?

☆樱花仙子☆ 提交于 2019-12-08 15:27:12
问题 I need to restart the app Console when the user press "R". I have this Console.WriteLine(message, "Rebuild Log Files" + " Press Enter to finish, or R to restar the program..."); string restar = Console.ReadLine(); if(restar.ToUpper() == "R") { //here the code to restart the console... } thanks 回答1: I don't think you really need restart whole app. Just run required method(s) after pressing R. No need to restart. 回答2: // Starts a new instance of the program itself System.Diagnostics.Process

Reading Key Press in Console App

风格不统一 提交于 2019-12-08 12:20:54
问题 I'm writing a small application which will wait for a key press, then perform an action based on what key is pressed. For example, if no key is pressed, it will just continue waiting, if key 1 is pressed, it will perform action 1, or if key 2 is pressed it will perform action 2. I have found several helpful posts so far, this one being an example. From this, I have the following code so far. do { while (!Console.KeyAvailable) { if (Console.ReadKey(true).Key == ConsoleKey.NumPad1) { Console

Get Indent of Excel Cell in new column using C#

匆匆过客 提交于 2019-12-08 10:38:28
问题 My objective is to add a new column (B) which stores the indent level values (1,2,3..etc) of column A. I do this operation before loading the excel into c# excel object. So my object should have new column B with values of indent for column A. if (xlWorkbook != null && xlWorkbook.Sheets.Count > 0) { Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1]; Excel.Range oRng = xlWorksheet.Range["B1"]; oRng.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, Excel

Simplest way to get an interactive console for my app

蹲街弑〆低调 提交于 2019-12-08 10:04:34
问题 I want a simple, interactive way to demo middle-tier features of my app which have not had a UI created yet. I want an interactive console. When my application (WPF but it shouldn't matter) boots up I would like to also start a console window. This window should run powershell (or ruby, or python, but preferably powershell) and have its scope set to access my ServiceLocator. Alternately, I could start up my app and attach to the process appdomain from an external powershell window and grab a

How do I get rid of circular numbers in my list

限于喜欢 提交于 2019-12-08 09:02:33
Okay, I know that this code is crude, and all around a messy, but I am no programmer, so bear with me. I have this code that lists a bunch of numbers, but I want it to not list any circular copies of the numbers. For example, if the number 111262 is on my list, I don't want 112621, 126211, 262111, 621112, or 211126 to be listed. Sorry, that number cannot be on the list. For a true example, if the number 111252 is on my list, I don't want 112521, 125211, 252111, 521112, or 211125 to be listed. Any help is appreciated! namespace Toric_Classes { class Program { static void Main(string[] args) {

How do I get rid of circular numbers in my list

人盡茶涼 提交于 2019-12-08 08:59:47
问题 Okay, I know that this code is crude, and all around a messy, but I am no programmer, so bear with me. I have this code that lists a bunch of numbers, but I want it to not list any circular copies of the numbers. For example, if the number 111262 is on my list, I don't want 112621, 126211, 262111, 621112, or 211126 to be listed. Sorry, that number cannot be on the list. For a true example, if the number 111252 is on my list, I don't want 112521, 125211, 252111, 521112, or 211125 to be listed.

Opening console from WinAPI gui program on mingw: '_fdopen' was not declared in this scope

风格不统一 提交于 2019-12-08 08:47:08
问题 I am currently working on WinAPI Gui application under MinGW. In debug version I want to open console and redirect stdin/stdout streams to it, so I can see diagnostic messages being printed in debug. I followed this article: http://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/ It works under Visual Studio, but when compiled on MinGW it spits this message, even if stdio.h is included: error: '_fdopen' was not declared in this scope Arguments for MinGW: mingw32-g++.exe