如何使startInfo.Arguments接受多个命令?

问题描述 投票:-2回答:1

嗨,我正在尝试运行此程序

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();

当我运行这个..回声Hi5被替换为66.如何使参数接受多个参数而不使用文件

c# powershell
1个回答
1
投票

它在你的参数中运行两个命令,你的while循环覆盖awsApiKey

尝试:

awsApiKey += process.StandardOutput.ReadLine();
© www.soinside.com 2019 - 2024. All rights reserved.