0

I have a small problem. Okay let's say from my C# console application I want to run a batch file that will take an argument. The string variable at the stop of my C# application will be the string argument to pass to the batch file. How would I go about doing it?

Here is my code so far my C# console program:

//String argument to pass to the batch file
string message = "Hello World";

System.Diagnostics.Process process = new System.Diagnostics.Process();

//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "Greetings.bat";
startInfo.Arguments = "/C " + message;
process.StartInfo = startInfo;
process.Start();

My Batch File

CLS
@ECHO OFF
ECHO %1          
PhilMY
  • 2,621
  • 21
  • 29
Sylvia Rosemond
  • 197
  • 1
  • 3
  • 11
  • 1
    possible duplicate of [C# Service cannot execute batch file?](http://stackoverflow.com/questions/361097/c-sharp-service-cannot-execute-batch-file) – Bernard Aug 11 '12 at 13:49
  • 1
    Or http://stackoverflow.com/questions/7101326/running-a-batch-file-from-c-sharp – Mark Jones Aug 11 '12 at 13:56

1 Answers1

0

You can give argument like this.

ProcessStartInfo psi = new ProcessStartInfo(filePath);
psi.WindowStyle = ProcessWindowStyle.Hidden; 
psi.Arguments = "value1";
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53