0

下面是在机器人框架模拟器中运行的 Azure SDK 机器人的示例意图。机器人通过返回字符串类型响应来识别我的意图。这只是给bot做的准备,当它识别到我的意图时,它应该运行CMD程序并在系统中执行命令,在CMD中执行命令并完成之后,它会返回一个响应,即命令已执行....但是,正如您在下面看到的,不幸的是,这不起作用。相反,机器人会立即返回所有响应,而无需等待并在 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;

我究竟做错了什么 ?

4

1 回答 1

0

这解决了我的问题:

我用 C# 编写了一个简单的 NodeJsServer 类,它可以帮助您完成这些事情。它可以在 GitHub 上找到。它有很多选项,您可以在特定目录中执行“npm install”命令,或者启动 NodeJs,检查当前状态(是否正在运行、是否正在编译、是否正在启动、是否正在安装)并最终停止 NodeJs。检查快速示例用法。

这是您尝试做的原始代码(主要从 NodeJsServer 类复制):

// 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");

于 2021-10-14T13:59:08.017 回答