0

I am looking for resources that have examples for creating a Console Application. I am past the "Hello World" stage but am stumped at the point where I need to run an application. I have the string that I need to run that I pulled from the batch file that I am trying to automate in a C# app. I need help with knowing which classes and namespaces have the functionality I need to run it.

Edit: Sorry for the poorly asked question. I'll rewrite it.

I am trying to create a console application that will replace a batch file that I have partially written. Some of the data and file manipulations that I need to do are more complex than can easily be done in a batch file. So far I am reading, writing, and manipulating the files just fine. I am having difficulty when trying figure out how to run a command to execute an application on the server with the proper arguments being passed in.

Update: a coworker gave me the following code snippit which is exactly what I needed to move forward. I am sorry the question was worded so badly.

 public static string MyDOSMethod() { ProcessStartInfo si = new ProcessStartInfo("cmd.exe"); si.RedirectStandardInput = true; si.RedirectStandardOutput = true; si.UseShellExecute = false; Process p = Process.Start(si); p.StandardInput.WriteLine(@"cd \windows\system32"); p.StandardInput.WriteLine("exit"); try { return p.StandardOutput.ReadToEnd(); } catch (Exception e) { return e.Message; } } 
2
  • 1
    Are you using Visual Studio? Creating a console application is really just a few button clicks. File->New Project-> Select Console Application. Otherwise you'll need to tell us what tools you're using or what else you're trying to accomplish. Commented Feb 9, 2011 at 20:18
  • This question needs clarification; I think he's asking how to run an executable from a C# application, but it can also be understood as a request about how to build a console application or how, in general, to find functionalities built-in in the .NET Framework. Commented Feb 9, 2011 at 20:27

3 Answers 3

3

The question is not perfectly clear, what I understood is "I need to start an application from my console application; what class can I use?"

My answer is: you should have a look at the static method Process.Start (and in general at the class Process of namespace System.Diagnostics).

Sign up to request clarification or add additional context in comments.

Comments

1

Have a look at this tutorial, it will guide you through the usage of Process.Start and ProcessStartInfo (which runs a process and gives you feedback)

1 Comment

Yeah, I think that's what they are asking for.
-1

I recommend this introduction to C# if your new to programming.

http://www.csharp-station.com/Tutorial.aspx

In order to compile you need a compiler and a GUI to edit code in is also nice :o) Here you can use the free version of Visual Studio:

http://www.microsoft.com/express/

In Visual Studio just click new select console application and i think you will get a "default application" like Hello World that you can run and build.

1 Comment

Thanks. But I'm not a new programmer, just have never had to write a console app.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.