如何解决从 c# 作为进程运行时,TeraTerm 宏会立即关闭
我目前正在开发一个来自 Visual Studio 的 Winforms 程序,该程序充当一大堆 teraTerm 宏的控制面板。我做了一个蠢事,没有将我的第一个工作版本添加到版本控制中,现在它停止工作了,我不知道为什么/如何恢复到我所拥有的。
功能是问题
using System;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Diagnostics;
...
namespace Test
{
public partial class MainWindow : Form
{
...
private void ImagesButton_Click(object sender,EventArgs e)
{
RunMacro("F:\\Users\\Isaac\\Documents\\LED Sign Commands\\Macros\\StartdisplayImages.ttl");
}
....
private void RunMacro(string userArgument)
{
panel1.Enabled = false;
StatusLabel.Visible = true;
Process process = new Process();
processstartinfo startInfo = new processstartinfo()
{
WindowStyle = ProcessWindowStyle.Hidden,#if DEBUG
FileName = "F:\\Users\\Isaac\\Documents\\LED Sign Commands\\teraterm\\ttpmacro.exe",#else
FileName = "..\\teraterm\\ttpmacro.exe",#endif
Arguments = userArgument
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
panel1.Enabled = true;
StatusLabel.Visible = false;
}
...
}
}
运行时,我看到 ttpmacro.exe
确实开始了,如果我省略 Arguments
赋值,那么它会提示我选择一个宏;如果我选择 StartdisplayImages.ttl
,它将按预期运行。但是,如果我将其作为上述参数包含在内,那么 ttpmacro
仍会打开但会立即关闭。没有错误出现(并且 RedirectStandardOutput/Error
什么也不产生),就好像 ttpmacro
接受了文件但不会对它做任何事情。我已确认两个文件路径均有效且正确。
虽然我没有添加版本控制,但我确实使用ILSpy提取了主文件,我在工作版本中的原始功能是:
private void ImagesButton_Click(object sender,EventArgs e)
{
RunMacro("/V ..\\Macros\\StartdisplayImages.ttl");
}
private void RunMacro(string userArgument)
{
panel1.Enabled = false;
StatusLabel.Visible = true;
Process process = new Process();
processstartinfo startInfo = (process.StartInfo = new processstartinfo
{
WindowStyle = ProcessWindowStyle.Hidden,FileName = "..\\teraterm\\ttpmacro.exe",Arguments = userArgument
});
process.Start();
process.WaitForExit();
panel1.Enabled = true;
StatusLabel.Visible = false;
}
来自已发布的版本,文件路径相对于应用程序的文件夹。除此之外,唯一的区别似乎是 process.StartInfo 分配方式的小语法,但我尝试恢复它但没有运气。目标框架是 .NET Core 3.1。 /V
标志不是问题;删除它只会使 ttpmacro
窗口在关闭之前运行的几分之一秒内可见。如果我使用命令行执行同一文件(例如 start "F:/Users/.../ttpmacro.exe" "F:/.../StartdisplayImages.ttl"
),它也会按预期运行。
解决方法
事实证明问题在于完整宏文件路径中的空格,用转义双引号将其括起来解决了问题。 TeraTerm 只是没有告诉我它没有找到文件。应该很明显,但我确信它在我之前调试时一直在工作,不需要引号。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。