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
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.
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?
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
Re: windows form .call console and give commands
still can not solve my problem.please give me some more line of code
Re: windows form .call console and give commands
Quote:
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#
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
Re: windows form .call console and give commands
Quote:
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:
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:
Quote:
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.
http://tech.reboot.pro/cheers.gif
Re: windows form .call console and give commands
Quote:
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?
Re: windows form .call console and give commands
Quote:
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!
Re: windows form .call console and give commands
Say Ace, were you able to make the MVP Summit in Bellevue last week?
Re: windows form .call console and give commands
Quote:
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.
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.
Re: windows form .call console and give commands
thanks dear. Now time to study all comments