Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Update (because I missunderstood the question):</p> <p>You can use the process class to start a process from your Forms application and just redirect the output stream.</p> <p>You would execute it like this:</p> <pre><code>ExecuteProcess(@"ConsoleApp.exe", "some arguments here"); // and now you can access the received data from the process from the // receivedData variable. </code></pre> <p>Code:</p> <pre><code>/// &lt;summary&gt; /// Contains the received data. /// &lt;/summary&gt; private string receivedData = string.Empty; /// &lt;summary&gt; /// Starts a process, passes some arguments to it and retrieves the output written. /// &lt;/summary&gt; /// &lt;param name="filename"&gt;The filename of the executable to be started.&lt;/param&gt; /// &lt;param name="arguments"&gt;The arguments to be passed to the executable.&lt;/param&gt; private void ExecuteProcess(string filename, string arguments) { Process p = new Process(); // Define the startinfo parameters like redirecting the output. p.StartInfo = new ProcessStartInfo(filename, arguments); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.OutputDataReceived += this.OutputDataReceived; // Start the process and also start reading received output. p.Start(); p.BeginOutputReadLine(); // Wait until the process exits. p.WaitForExit(); } /// &lt;summary&gt; /// Is called every time output data has been received. /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The sender of this callback method.&lt;/param&gt; /// &lt;param name="e"&gt;The DataReceivedEventArgs that contain the received data.&lt;/param&gt; private void OutputDataReceived(object sender, DataReceivedEventArgs e) { this.receivedData += e.Data; } </code></pre> <p>Old Answer:</p> <p>Basically you will get access to all specified command line arguments by accessing the "args" parameter in the main method. The little example prints all specified command line arguments (they are spereated with a space-character between them) to the console and waits for a key to be pressed before exiting.</p> <p>Example:</p> <pre><code>/// &lt;summary&gt; /// Represents our program class which contains the entry point of our application. /// &lt;/summary&gt; public class Program { /// &lt;summary&gt; /// Represents the entry point of our application. /// &lt;/summary&gt; /// &lt;param name="args"&gt;Possibly spcified command line arguments.&lt;/param&gt; public static void Main(string[] args) { // Print the number of arguments specified to the console. Console.WriteLine("There ha{0} been {1} command line argument{2} specified.", (args.Length &gt; 1 ? "ve" : "s"), args.Length, (args.Length &gt; 1 ? "s" : string.Empty)); // Iterate trough all specified command line arguments // and print them to the console. for (int i = 0; i &lt; args.Length; i++) { Console.WriteLine("Argument at index {0} is: {1}", i, args[i]); } // Wait for any key before exiting. Console.ReadKey(); } } </code></pre> <p>Don't be confused by the arguments in the first WriteLine statement, I just wanted to print singular and plural correctly.</p> <p>You can specify the command line argument either by passing them on the command line:</p> <p>Example: Your.exe argument1 argument2 argument3</p> <p>Or in the IDE by using the properties of the project (right click on your project in the solution explorer -> Properties -> Debug -> Command line arguments)</p> <p>I hope I understood your question correctly and this helps ;-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload