Any way to run C# through the Terminal? - c#

I'm looking for something like JS/Ruby engines that enable you to run commands from terminal. Something like to what LINQPad do but much more simple.
I know C# is not design to be used a a script but would be helpful to have, for example, a mono console application with Main() awaiting for commands came from terminal.
May can I implement such a thing?

Have you tried the interactive C# shell?
There is also a GUI version called gsharp
More here

You can try Jon Skeet's Snippy. Source code is also available so you can tweak it or just use as a sample to create your own.
Also, Visual Studio has build in solution - "Debug->Windows->Immediate". Just create empty console project and start typing commands in the Immediate window.

Related

How to communicate between two different applications (Web Application and Console Application) using Ctr+c , Ctr+v , Entre [duplicate]

I am developing a console application in C#, and was wondering if there was a way to get the "copy-paste" or "mark-paste" functionality into my application, similar or identical to that of the standard Windows command prompt. Is this a wild goose chase or a simple application variable?
I've copied text from the Console window and pasted it into another source many times.
It's there as default in a Console application;
Right click the console border:
Select Edit > Mark:
Drag over the text you want using the mouse (Or use the arrow keys) to select the text you want:
Again, right click on the console border and select Edit > Copy:
From here you can paste it into another application as you would with any other text.
This was taken from a C# Console application and the only code entered was the command to write to the console, no settings were changed.
Hope this helps!
Thank you Sean for making me realize the complete idiocy of this question. Let me be an example to others to not jump on the conclusion train.
Sean pointed out that "copy-paste can be done using cmd.exe's built-in functionality", making me recognize that, yes, absolutely duh, when you run your command line application in Windows it already has this functionality available.
I erred by jumping to conclusions, for I was doing all my initial testing with the DEBUG execution through the IDE, and vshost does not give you that functionality.
A quick "Start Without Debugging" revealed my short-sightedness.
I don't know why this isn't included in any answer, but as Robert H. stated in a comment, this is absolutely useful information, in case you came here by searching for this problem in a VisualStudio environment:
Run a console app in the debugger (F5). You cannot copy or paste.
Run it outside the debugger (Control + F5). Now, you can copy and paste.
Worked like a charm for me. Thanks Robert H.!
To clarify, is the default command prompt behavior not working at all for you, or just not how you want it to?
From what I understand, it is the terminal implementation that supplies the copy/paste behavior, and what it provides doesn't match rest of Windows. To change this behavior, you'd have to switch the program that implements the terminal. Here are a couple programs that come up on a google search for "command prompt replacement":
http://www.powercmd.com/
http://sourceforge.net/projects/console/
Of those two, I think one of my friends at work tried "Console". It did enough of what he wanted that he didn't feel the need to keep looking.
If you just want your output for this specific program to work more like the rest of Windows, your other choice is to make it a Windows program.
Edit: Fixed the URL to Console. Was posting to someone's blog that linked to it, before :)
Maybe I am late but there is a shortcut for pasting text in Console Window in c#. Press Alt+Space then 'E' then 'P' and there you have your text pasted in the Console Window

Forward input to powershell, read output from it without the user seeing a console c#

Is there any way I could have an application that acts as a different interface for a powershell prompt, like the ISE does? I just want to make it visually different. I'm thinking something to do with stdin and stdout, but i'm not totally sure how to make that work in C#. As well as the issue of hiding the console window.
Sure you can use the PowerShell engine API to host PowerShell within a WPF or WindowsForms application. See this MSDN topic on hosting PowerShell in your own application.

Getting debugger context in C# interactive

C# Interactive seems a lot more powerful than the Immediate Window (at least it handles lambda expressions that are often used in LINQ - see Visual Studio debugging "quick watch" tool and lambda expressions), but it looks like it can't be used as a replacement as it doesn't know about the debugger context. Is there a way to have access to the debugger context?
I've seen Getting debugger context in F# interactive and it might require the same things, but maybe there are new/different things available.
http://extendedimmediatewin.codeplex.com/ could be useful but looks quite dead, although someone said on Oct 18 2011 that he was planning to port it to VB.Net ( http://extendedimmediatewin.codeplex.com/discussions/75589 ).
Not a complete solution, but in VS2015, after you've run Initialize Interactive with Project, you can use Debug > Attach to Process to connect to the InteractiveHost.exe process.
You can then debug functions from your project. You won't be able to debug one-off functions in the Interactive window, though, as Kevin explained.
As as side note, https://stackoverflow.com/a/40650343/467110 points out that you may have to have a C# Interactive window open before you open your solution in order to successfully Initialize Interactive with Project
Disclaimer: I work for Microsoft on the Roslyn team.
Unfortunately, we don't have a way to get the debugger context right now. We are aware that it would useful, and as we get more of the core deliverables for Roslyn completed we hope to investigate more and see what can be done.
Inside C# Interactive you can run
System.Diagnostics.Debugger.Launch();
to request a debuger, whereby you will get a window asking you to choose one of the open Visual Studio instances or a new instance to attach. Assuming you used "Load Interactive with the Project" option of Visual Studio - any breakpoints in the open Solution will now be hit when code is ran by Interactive.
If you need the debugger without pre-existing code - you can now insert
System.Diagnostics.Debugger.Debug();
calls into the code you put into Interactive (but it does have to go in one 'chunk', i.e. one press of 'enter'), and you will be able to examine local vars via 'locals' window and run code against interactive context via 'immediate' window.

A Simple application that can run in windows task bar

I want to write a very simple application, containing a pop-up menu when user click on it, that will appear in windows task bar, exactly like language bar, this is the only need. it does not concatin any more functionality at the time being.
Does anybody know where to start or do you have any sample code for it. I really do not know where to start since I am a Newbie!
Thanks in advance
Try having a look at the NotifyIcon class.
You are looking for ITrayDeskBand but good luck with getting anything out of the MSDN documentation.
I suggest a web search for ITrayDeskBand and looking at the top hits that aren't on MSDN!
For example, this from the Code Project looks useful. Note that since this is a shell extension, most of the code you find will be native because .NET shell extensions are somewhat frowned upon.
You need to develop a ToolBand for this.
You can either develop one yourself or use a library like EZShellExtensions.

Getting debugger context in F# interactive

Is it possible to somehow get the debugger context in F# interactive? For instance, if I hit a breakpoint in C# project then I would like to work with local variables in F# interactive, the same way I can work with them in immediate window. Is there any way to do so? Or do I need to create a debugger visualizer for that?
Neither. You need to create an Expression Evaluator for it. Not sure if C# can be extended, but there is a sample in the VS SDK (the 2008 one at least).
I've make very similar tool for Python, so I'm just using Python shell to evaluate some expressions like in Immediate Window. For this I've created a very simple VS Add-In and Python helper script.
You can find sources on github - https://github.com/dp0h/VsImmediate

Categories