console-application

How to read user input in c# console

假如想象 提交于 2019-12-02 07:04:48
I guess this should be very simple to you guys, but very difficult to me because im new to c#. I have a simple "pacient" class. public class Pacient { public Pacient(string _name, string _lastName, DateTime _date, string _phone, string _email) { name = _name; lastname = _lastName dateOfBirth = _date; phone_num = _phone; email = _email; } private string name; public string Name { get { return name; } set { name = value; } } etc... Now i want to read the input user types in console... How do i do that? It works with pre-typed names, like shown bellow.. Pacient John = new Pacient("John", " Doe ",

.net console app lifecycle - working around a pre-start initialization error from BuildManager.GetReferencedAssemblies

走远了吗. 提交于 2019-12-02 06:52:55
I'm trying to iterate through the referenced assemblies in my console app. I have been doing this with BuildManager.GetReferencedAssemblies in other projects, but in my console application, I get an InvalidOperationException: This method cannot be called during the application's pre-start initialization stage. To my knowledge, there isn't a way to delay execution in a console app. You do it in static void Main, or you don't do it at all... Anyone have any suggestions on how to get around this? Cerebrate BuildManager.GetReferencedAssemblies() from the System.Web.Compilation namespace? So far as

how to call “ static void Main(string[] args) ”in the class again

心已入冬 提交于 2019-12-02 06:45:53
问题 i am new in C# and working on Console Applications now a days i wrote the following code : Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ch06Ex01 { class Program { static void Write() { Console.WriteLine("Please enter any string..!!"); } static void Main(string[] args) { Write(); string name = Console.ReadLine(); Write(); string name1 = Console.ReadLine(); Write(); string name2 = Console.ReadLine();

In dotnet core how can I ensure only one copy of my application is running?

柔情痞子 提交于 2019-12-02 06:45:49
In the past I have done something like this private static bool AlreadyRunning() { var processes = Process.GetProcesses(); var currentProc = Process.GetCurrentProcess(); logger.Info($"Current proccess: {currentProc.ProcessName}"); foreach (var process in processes) { if (currentProc.ProcessName == process.ProcessName && currentProc.Id != process.Id) { logger.Info($"Another instance of this process is already running: {process.Id}"); return true; } } return false; } Which has worked well. In the new dotnet core world everything has a process name of dotnet so I can only run one dotnet app at a

Python PSS/E get output as variable

↘锁芯ラ 提交于 2019-12-02 06:14:43
I am power engineer and I often use python in PSS/E program. I am stacked and I want your help as programmers. I have this small code: import os,sys PSSE_LOCATION = r"C:\Program Files\PTI\PSSE33\PSSBIN" sys.path.append(PSSE_LOCATION) os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION import psspy import redirect redirect.psse2py() #-------------------------------- # PSS/E Saved case CASE = r"""D:\xxx\Desktop\TESTING\SUMMAX.sav""" if __name__ == '__main__': psspy.psseinit(2000) psspy.case(CASE) psspy.fnsl( options1=0, # disable tap stepping adjustment. options5=0, # disable switched

Logon failure: unknown user name or bad password.error while accessing other server

六眼飞鱼酱① 提交于 2019-12-02 05:11:39
问题 I'm accessing other server with the login credentials. My problem is if I run the code initially, it wil show the error as Logon failure: unknown user name or bad password but if I try running the code after connecting to the server once through the command prompt. Then, the application works fine and it does not throw any error. So, daily I need to connect to server once through command prompt in order to run the application without errors. Here is my code: static void main() { string

Closing function in a VB.NET console application

筅森魡賤 提交于 2019-12-02 04:26:52
问题 How can I fire off a function when it detects the console closing when using Environment.Exit(0) ? 回答1: The simplest way of doing this is probably to handle the AppDomain.ProcessExit event, which is raised when the application's parent process exits. For example: Module MyApp Sub Main() ' Attach the event handler method AddHandler AppDomain.CurrentDomain.ProcessExit, AddressOf MyApp_ProcessExit ' Do something ' ... Environment.Exit(0) End Sub Private Sub MyApp_ProcessExit(sender As Object, e

Trying to get StandardOutput after running a console process

巧了我就是萌 提交于 2019-12-02 04:21:22
I can run a console process using the following C# code. The goal is also to collect all the output from such process: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Arguments = commandLine; proc.StartInfo.FileName = "signtool.exe"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); if (proc.WaitForExit(10000)) { Debug.WriteLine(proc.StandardOutput.ReadToEnd()); } What I receive is this: "Done Adding Additional Store\r\n" But when I do the same from a Windows command line I get this: Done Adding Additional

How to redirect stdout and stderr streams (Multiplatform)?

旧城冷巷雨未停 提交于 2019-12-02 04:15:39
问题 I'm writing GL application that uses external libs, which print errors to the console. I want to catch that and print in the in-game console. PS: Sorry, for my bad english.... 回答1: There are two basic approaches you could take to this: If the libraries all use std::cout for the IO you want to capture you can write your own basic_streambuf. You can then just call std::cout.rdbuf(mybufinst); to replace the streambuffer, for example using the std::basic_stringbuf : #include <sstream> #include

JTextArea as console

╄→尐↘猪︶ㄣ 提交于 2019-12-02 03:54:41
I have posted two pieces of code below. Both codes work fine individually. Now, when I run the file Easy, and click on the "Start" button, I want the class AddNumber to be implemented. I mean to say that, instead of the AddNumber running on the console, is there any way I could make AddNumber run in the JTextArea i have created in the first class upon clicking the "Start" button? I thought maybe by action listener?(the way we do in case of buttons) But I'm not sure. Is there any other way to make my JTextArea act as a console for the other .java files? import java.awt.*; import javax.swing.*;