-
February 22nd, 2013, 07:21 AM
#1
windows form .call console and give commands
I cant find solution for that
Its a windows forum
on button click open console and readline to assign the value to $tring or int array
and later show in mbox
in console app.itss so easy
but on windows form applcation how to call console? and assign value to $tring or int
-
February 23rd, 2013, 10:37 AM
#2
Re: windows form .call console and give commands
What you do is launch the [console] application using the Process class and then redirect the stdinput/stdoutput to the launching program.
-
February 23rd, 2013, 04:30 PM
#3
Re: windows form .call console and give commands
thank you sir AMArjay.but can you give an ex? or some piece of code how to do?
-
February 23rd, 2013, 05:24 PM
#4
Re: windows form .call console and give commands
You can P/Invoke AllocConsole():
Code:
[DllImport("kernel32.dll")]
static extern bool AllocConsole();
private void MainMethod()
{
if (AllocConsole())
{
Console.WriteLine("Hello world!");
}
else
{
// Error?
}
}
Shouldn't need to use the Process class here if you just want to open a console window.
You may want this link as reference: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
February 24th, 2013, 08:18 AM
#5
Re: windows form .call console and give commands
still can not solve my problem.please give me some more line of code
-
February 24th, 2013, 12:32 PM
#6
Re: windows form .call console and give commands
![Quote](images/misc/quote_icon.png) Originally Posted by AceInfinity
You can P/Invoke AllocConsole():
Code:
[DllImport("kernel32.dll")]
static extern bool AllocConsole();
private void MainMethod()
{
if (AllocConsole())
{
Console.WriteLine("Hello world!");
}
else
{
// Error?
}
}
Shouldn't need to use the Process class here if you just want to open a console window.
You may want this link as reference: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
I think you shared me c++ code and c++ link.its c#
-
February 24th, 2013, 03:28 PM
#7
Re: windows form .call console and give commands
If I understand the problem, you are trying to set the input and read the output of a console app? If so, then AllocConsole isn't going to help.
AllocConsole only helps if you want to open a console window to your process, and if you are trying to do that there is an even easier way to create a console window for your forms app - that is to simply set the application type of your forms app to 'console app'. A console window will then open along side the forms window.
But as I said, that isn't going to help if the console window you are interested in is in another process. If you are trying to send and receive text in another console app process, you are going to have to open that process with the Process class and redirect stdin and stdout as I mentioned earlier.
There is a lot of help available to do this - just search bing or google for "redirect stdinput process C#".
Here's is one such article...
http://www.codeproject.com/Articles/...t-of-an-applic
-
February 24th, 2013, 08:18 PM
#8
Re: windows form .call console and give commands
![Quote](images/misc/quote_icon.png) Originally Posted by yousufshah
I think you shared me c++ code and c++ link.its c#
I know I did, this is why I mentioned "P/Invoke" http://msdn.microsoft.com/en-us/library/aa446536.aspx
That code I shared with you is not C++ either.
![Quote](images/misc/quote_icon.png) Originally Posted by Arjay
If I understand the problem, you are trying to set the input and read the output of a console app? If so, then AllocConsole isn't going to help.
AllocConsole only helps if you want to open a console window to your process, and if you are trying to do that there is an even easier way to create a console window for your forms app - that is to simply set the application type of your forms app to 'console app'. A console window will then open along side the forms window.
But as I said, that isn't going to help if the console window you are interested in is in another process. If you are trying to send and receive text in another console app process, you are going to have to open that process with the Process class and redirect stdin and stdout as I mentioned earlier.
There is a lot of help available to do this - just search bing or google for "redirect stdinput process C#".
Here's is one such article...
http://www.codeproject.com/Articles/...t-of-an-applic
I read this:
I cant find solution for that
Its a windows forum
on button click open console and readline to assign the value to $tring or int array
and later show in mbox
in console app.itss so easy
but on windows form applcation how to call console? and assign value to $tring or int (*array?)
1. "It's a Windows Form (application)"
2. "On a button click, I want to open console and readline to assign the value to a string or integer array and later show in a MessageBox."
3. "In a console app, it is so easy, but on windows form applcation how do I call the console?"
He didn't mention anything about a console based program, he only mentioned calling the console. If he wanted user input to the console, then he would have to create a program to do this and just act as a variable initializer, which I don't think is what he's doing...
I could be wrong, but he never mentioned a console program at all. He only asked how to call the console. I would wonder why he doesn't just use a TextBox though? Using the console just for user input to a string variable seems unethical to me.
I just went by exactly what he said he wanted to do, and no more.
Last edited by AceInfinity; February 24th, 2013 at 08:23 PM.
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
February 24th, 2013, 08:54 PM
#9
Re: windows form .call console and give commands
![Quote](images/misc/quote_icon.png) Originally Posted by AceInfinity
He didn't mention anything about a console based program, he only mentioned calling the console. If he wanted user input to the console, then he would have to create a program to do this and just act as a variable initializer, which I don't think is what he's doing...
I could be wrong, but he never mentioned a console program at all. He only asked how to call the console. I would wonder why he doesn't just use a TextBox though? Using the console just for user input to a string variable seems unethical to me.
I just went by exactly what he said he wanted to do, and no more.
Yeah, sometimes it's tough trying to figure out what an OP is trying to do.
Generally, many [beginner] folks confuse a console app with the console window that Windows displays the app in. Because of this, they think the way to input data into a console app is to somehow enter it into the console window. Likewise, to get the output of a console app, they usually think they need to somehow scrape the console window.
While this can be done, it generally isn't the best approach in terms of robustness, so the more common approach is to use the redirect method I've mentioned.
Perhaps the OP will post back to clarify?
-
February 24th, 2013, 08:57 PM
#10
Re: windows form .call console and give commands
![Quote](images/misc/quote_icon.png) Originally Posted by Arjay
Yeah, sometimes it's tough trying to figure out what an OP is trying to do.
Generally, many [beginner] folks confuse a console app with the console window that Windows displays the app in. Because of this, they think the way to input data into a console app is to somehow enter it into the console window. Likewise, to get the output of a console app, they usually think they need to somehow scrape the console window.
While this can be done, it generally isn't the best approach in terms of robustness, so the more common approach is to use the redirect method I've mentioned.
Perhaps the OP will post back to clarify?
You're not wrong though, I'm not saying that. I'll wait and see until OP can clarify what he's willing to do before going further in a specific direction. It's like a forest, you don't start going in any one direction unless you know where you are, and where you want to be headed, otherwise you're more likely to get lost.
Cheers!
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
February 24th, 2013, 08:59 PM
#11
Re: windows form .call console and give commands
Say Ace, were you able to make the MVP Summit in Bellevue last week?
-
February 24th, 2013, 09:01 PM
#12
Re: windows form .call console and give commands
![Quote](images/misc/quote_icon.png) Originally Posted by Arjay
Say Ace, were you able to make the MVP Summit in Bellevue last week?
Nope... Sadly. I did want to go, but no real way of transportation for me, and I am of the slightly younger audience among MVP's. It would have been a good opportunity to meet usasma and jcgriff, who I know fairly well since I was initially awarded in 2012.
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
February 24th, 2013, 09:11 PM
#13
Re: windows form .call console and give commands
If we're all re-awarded next year, we'll have to invite you to the infamous Code Guru Vodka night.
-
February 26th, 2013, 10:49 AM
#14
Re: windows form .call console and give commands
thanks dear. Now time to study all comments
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|