如果识别出意图,如何 运行 CMD 并插入来自 bot azure 程序的命令?

How to run CMD and plug in a command from a bot azure program if intent is recognized?

下面是 运行bot 框架模拟器中 Azure SDK 机器人的示例意图。机器人通过 returning 字符串类型响应识别我的意图。这只是bot的一个准备,当它识别出我的意图后,它应该运行CMD程序并执行系统中的命令,在CMD中执行命令完成后,它会return 命令已执行的响应....但是,正如您在下面看到的,不幸的是,这不起作用。相反,机器人会立即 return 发送所有响应而无需等待 运行 在 CMD 中输入命令。

case WebAppBotTester.Intent.TestPageOne:
   var getSearchActionText = "Redirecting to the Action and run CMD, wait...";
   var getSearchActionMessage = MessageFactory.Text(getSearchActionText, getSearchActionText, InputHints.IgnoringInput);
   await stepContext.Context.SendActivityAsync(getSearchActionMessage, cancellationToken);
   string command = @"cd ..\..& cd tests & npx [MAKE ACTION..]";
   ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");
   cmdsi.Arguments = command;
   Process cmd = Process.Start(cmdsi);
   cmd.WaitForExit();
   var getresultActionText = "The result is ready!";
   var getresultActionMessage = MessageFactory.Text(getresultActionText , getresultActionText, InputHints.IgnoringInput);
   await stepContext.Context.SendActivityAsync(getresultActionMessage, cancellationToken);
break;

我做错了什么?

这解决了我的问题:

I have written a simple NodeJsServer class in C# that can help you with these things. It is available on GitHub here. It has a lot of options, you can execute 'npm install' commands in specific directories, or start NodeJs, check the current status (is it running, is it compiling, is it starting, is it installing) and finally stop the NodeJs. Check the quick example usage.

This is the raw code (copied mostly from the NodeJsServer class) of what you are trying to do:

// create the command-line process
var cmdProcess = new Process
{
    StartInfo =
    {
        FileName = "cmd.exe",
        UseShellExecute = false,
        CreateNoWindow = true, // this is probably optional
        ErrorDialog = false, // this is probably optional
        RedirectStandardOutput = true,
        RedirectStandardInput = true
    }
};

// register for the output (for reading the output)
cmdProcess.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
{
    string output = e.Data;
    // inspect the output text here ...
};

// start the cmd process
cmdProcess.Start();
cmdProcess.BeginOutputReadLine();

// execute your command
cmdProcess.StandardInput.WriteLine("quicktype --version");