-2

Hi I'm trying to run this program

string exeDir = "C:\\svn\\Services\\trunk\\In4m\\Services.In4m.MachineStatusServices\\Scripts\\aws-newAPIKey";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = @"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe";
string powershellcommands = "echo 'Hi5'; echo '66' ";
startInfo.Arguments = powershellcommands;
//startInfo.WorkingDirectory = exeDir;


Process process = new Process();
process.StartInfo = startInfo;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string awsApiKey=String.Empty;
while (!process.StandardOutput.EndOfStream)
{
    awsApiKey = process.StandardOutput.ReadLine();

    // do something with line
}
Console.WriteLine(awsApiKey);
process.WaitForExit();

When I run this.. the echo Hi5 gets replaced by 66. How to make arguments accept multiple parameters without using a file

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
the_coder_in_me
  • 143
  • 3
  • 15

1 Answers1

1

It's running both commands in your argument, your while loop is overwriting awsApiKey.

try:

awsApiKey += process.StandardOutput.ReadLine();
WillFM
  • 353
  • 1
  • 13