c# - 如果识别到意图,如何运行 CMD 并从 bot azure 程序插入命令?
问题描述
下面是在机器人框架模拟器中运行的 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;
我究竟做错了什么 ?
解决方案
这解决了我的问题:
我用 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");
推荐阅读
- typescript - 如何在同时使用 babel 和 typescript 时避免重复的转换?
- layout - 为什么这种布局结果如此缓慢,尤其是在移动设备上?
- java - 在多维数组中划分元素?
- android-studio - Android Studio AVD Manager 模拟器无法在 Windows 10 中下载它发生了很多次
- google-cloud-firestore - 如何使用 OR [ || ] Cloud Firestore 规则中的运算符
- c++ - 如何启用使用另一个类的静态方法的模板函数的自动推导,从而消除冗长的调用者代码
- python - 显示模型输出的问题.ManyToManyField(User)
- javascript - 错误:无效登录:535-5.7.8 不接受用户名和密码
- react-native - 如何获取博览会屏幕的屏幕截图?
- python - AttributeError:“节点”对象在 Keras 中没有属性“输出掩码”