ina
ina

Reputation: 19534

Running a console app with arguments from C# - GUI Hookup Advice

(Warning: This is a C# n00b question! Trying to learn a bit of C# while making things easier for a console app I run frequently.)

I'm trying to run a console application (consoleapp.exe) without having to manually type in the arguments each time - The command is typically of this form:

C:/consoleapp.exe --username (uname) --password (pass) --inputfile "c:/pathtofile/filename.xml"

Using C# I might even be able to load up a Windows explorer file prompt, instead of having to manually type in the file path each time. How would I go about doing this?

I tried the snippet at this link. I got it to work by just replacing the ApplicationPath with the path to my cojnsole app, and ApplicationArguments with the arguments shown in the format above, except I'm not sure how to hook up the parameters with the VC# GUI tools, or to relay the output I get from the original console app back.

Upvotes: 2

Views: 12340

Answers (2)

Grzegorz Gierlik
Grzegorz Gierlik

Reputation: 11232

This is not answer to question above -- see comments to question above.

In Project Properties dialog, on Debug tab you can define command line arguments and working directory.

Upvotes: 10

Dyppl
Dyppl

Reputation: 12381

here's some sample code of running a console app with parameters and processing the output.

private static Process PrepareTfProcess(string args)
{
    return new Process
                      {
                          StartInfo =
                              {
                                  CreateNoWindow = true,
                                  FileName = @"consoleapp.exe",
                                  Arguments = args,
                                  RedirectStandardOutput = true,
                                  UseShellExecute = false
                              }
                      };

}

//...
using (var process = PrepareTfProcess("--param1 --param2"))
{
    while (!process.StandardOutput.EndOfStream)
    {
        string str = process.StandardOutput.ReadLine();
        // Process output lines here
    }
}
//...

Upvotes: 1

Related Questions