我一直在努力尝试从C#执行powershell命令并在提示时向其发送用户输入
这是我的代码>
我想听一个提示并在程序要求时输入一些数据
例如,如果我想执行命令ftp
,然后当它提示我输入时,我想键入quit
。我可以用Powershell做到这一点吗?
private string RunScript(List<string> scriptText)
{
StringBuilder stringBuilder = new StringBuilder();
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.Add("Out-String");
foreach (string str in scriptText)
{
Command cmd = new Command(str, false); ;
pipeline.Commands.Add(cmd);
}
pipeline.InvokeAsync();
while (!pipeline.Output.EndOfPipeline)
{
stringBuilder.AppendLine(pipeline.Output.ToString());
}
runspace.Close();
return stringBuilder.ToString();
}
答案 0 :(得分:0)
目前还不清楚你想要实现的目标,但是:
{
"_id": {
"defect": "aaaa",
"week: 1
},
"sumOfCost": 213213
}
{
"_id": {
"defect": 'aaaa',
"week": 2
},
"sumOfCost: 123213
}
...
,而且我认为也找不到Test1
示例:
Test2