Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a question i can't seem to find an answer to, and i hope someone can help :)
I want to create a application similar to Yakuake, Tilda, etc.

Currently i have been able to achive something simelar to this by using a textbox to enter the commands and another textbox to display the results using streams, but thats not a real shell now is it.

Console2(http://sourceforge.net/projects/console/[^]) does pretty much what I want to acheive, but not 100%.

So is there anyone here that know what technique that have been used in Console2? (And similar programs?) Another program that does this is the Powershell ISE, it's divided in 3 sections with a interactive powershell-shell at the bottom(So it should be do-able to do this in other programs aswell, right?)

Anyways, I hope someone here are able to put me in the right direction :)


Sincerely
Karl-Einar
Posted

1 solution

This is a well-known thing, which is implemented in the class System.Management.Automation.PowerShell, please see:
http://msdn.microsoft.com/en-us/library/system.management.automation.powershell%28v=vs.85%29.aspx[^].

You can find a simple code sample here:
http://www.dougfinke.com/blog/index.php/2010/04/08/how-to-embed-powershell-within-a-c-application/[^].

Now, this sample uses a default console as it comes in console applications. You can use console in your Forms applications; you can show no output; or you can show output in some System.Windows.Forms control. I would recommend using ListBox to have the look closest to the traditional console. You can present the work of the shell in any other way.

If the execution of the shell can take some noticeable time, you should run it all in a separate thread. If you need to present some data produced by this PowerShell thread, you will need to use UI thread invocation, which I described in detail in my past solutions:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references to my past answers on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
v2
Comments
ProEnggSoft 21-Feb-12 18:48pm    
Good Info. Hence Voted 5.
Sergey Alexandrovich Kryukov 21-Feb-12 20:47pm    
Thank you.
--SA
Karl-Einarb 22-Feb-12 4:46am    
Thank you very much for the answer! :)
I haven't been able to test it yet, but the listbox idéa was a good one.
Sergey Alexandrovich Kryukov 22-Feb-12 11:59am    
You are very welcome.
It works, for sure.

Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900