commandline problem?

  • Thread starter Thread starter nick
  • Start date Start date
N

nick

Hi all:

In the winform i want to run commandline with return value(string),
then display this string in winform textbox.

anyone has idea about that?

Thanks

Nick
 
Are you asking how to accept input into your WinForms app via the command line?

If so:

public static void Main(string[] args)
{
foreach (string arg in args)
System.Windows.Forms.MessageBox.Show(arg);
}

Executing an application with the above code as the Main entry point and the following command line will produce two message boxes,
each with one of the arguments specified:

MyApp.exe "c:\Path\File Name.txt" -Switch1
 
Hi Dave:
there is the thing:
i have a executable command for exampl is :abc
you can type abc in commandline then it will return a string.

then i want to use winform to do this, so write a C# code doing same
function as type abc in commandline window and return a string.
finally show this string in textfields.

the whole process won't pop up commandline window at all.

Thanks

Nick

Dave said:
Are you asking how to accept input into your WinForms app via the command line?

If so:

public static void Main(string[] args)
{
foreach (string arg in args)
System.Windows.Forms.MessageBox.Show(arg);
}

Executing an application with the above code as the Main entry point and
the following command line will produce two message boxes,
 
You must change the Project output to "Console Application".

I think that Console.* uses an existing Console window, or creates one if it doesn't already exist for the current process. Your
output will go to a new console window in the context of a "Windows Application" Project, however, it will not remain open for user
input.

If you look real hard you may see the window pop-up for a second, display your string, and then close.

I'm not aware of any means for preventing a Console window from closing unless it is running in a "Console Application" Project.

Anyway, it's probably not a good design to have a Windows app displaying a Console window to display status, etc.

Use a StatusBar control, MessageBox.Show or EntryLog, etc..

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
nick said:
Hi Dave:
there is the thing:
i have a executable command for exampl is :abc
you can type abc in commandline then it will return a string.

then i want to use winform to do this, so write a C# code doing same
function as type abc in commandline window and return a string.
finally show this string in textfields.

the whole process won't pop up commandline window at all.

Thanks

Nick

Dave said:
Are you asking how to accept input into your WinForms app via the command line?

If so:

public static void Main(string[] args)
{
foreach (string arg in args)
System.Windows.Forms.MessageBox.Show(arg);
}

Executing an application with the above code as the Main entry point and
the following command line will produce two message boxes,
each with one of the arguments specified:

MyApp.exe "c:\Path\File Name.txt" -Switch1
 
nick said:
Hi all:

In the winform i want to run commandline with return value(string),
then display this string in winform textbox.

anyone has idea about that?

Drop a button and a textbox onto a form. Create a batch file
(C:\test.bat) with something that will generate output (I used "ping
127.0.0.1"). Add this code to the button click event.


ProcessStartInfo ps = new ProcessStartInfo(@"C:\test.bat");
ps.RedirectStandardOutput = true;
ps.UseShellExecute = false;
Process p = Process.Start(ps);
this.textBox1.Text = p.StandardOutput.ReadToEnd();

Is that what you were after?
 
Back
Top