简体   繁体   English

当从 c# 作为进程运行时,TeraTerm 宏会立即关闭

[英]TeraTerm macro immediately closes when run as a process from c#

I'm currently working on a Winforms program from Visual Studio that acts as a control panel for a whole bunch of TeraTerm macros.我目前正在开发一个来自 Visual Studio 的 Winforms 程序,它充当一大堆 TeraTerm 宏的控制面板。 I did a dumb and didn't add my first working version to version control, and now it's stopped working and I have no idea why/how to get back to what I had.我做了一个愚蠢的事情,没有将我的第一个工作版本添加到版本控制中,现在它停止工作了,我不知道为什么/如何恢复我所拥有的。

The function is question is function 问题是

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;
        }

        ...

    }
}

When run, I see that ttpmacro.exe does start, and if I omit the Arguments assignment then it will prompt me to select a macro;运行时,我看到ttpmacro.exe确实启动了,如果我省略Arguments分配,那么它会提示我输入 select 宏; if I select StartDisplayImages.ttl , it will run as expected.如果我 select StartDisplayImages.ttl ,它将按预期运行。 If I include it as an argument as above, however, then ttpmacro still opens but immediately closes.但是,如果我将它作为上述参数包含在内,则ttpmacro仍会打开但会立即关闭。 No error comes up (and RedirectStandardOutput/Error produce nothing), it's as if ttpmacro accepts the file but won't do anything with it.没有出现错误(并且RedirectStandardOutput/Error什么也没产生),就好像ttpmacro接受文件但不会对它做任何事情。 I've confirmed both filepaths are valid and correct.我已经确认两个文件路径都是有效且正确的。

While I didn't add version control, I did extract the main file using ILSpy, and my original functions in the working version were:虽然我没有添加版本控制,但我确实使用 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;
    }

Being from the published release, the filepaths are relative to the folder of the application.来自已发布的版本,文件路径是相对于应用程序的文件夹的。 Other than that, the only difference seems to be minor syntax in how process.StartInfo is assigned, but I tried reverting that with no luck.除此之外,唯一的区别似乎是如何分配 process.StartInfo 的小语法,但我尝试恢复它没有运气。 Target framework is .NET Core 3.1.目标框架是 .NET Core 3.1。 The /V flag isn't the issue; /V标志不是问题; removing it simply makes the ttpmacro window visible for the fraction of a second it runs before closing.删除它只会使ttpmacro window 在关闭前运行的几分之一秒内可见。 If I use a commandline execution of the same file (eg start "F:/Users/.../ttpmacro.exe" "F:/.../StartDisplayImages.ttl" ), it also runs as expected.如果我使用同一文件的命令行执行(例如start "F:/Users/.../ttpmacro.exe" "F:/.../StartDisplayImages.ttl" ),它也会按预期运行。

It turned out the problem was the spaces in the full macro filepath, and surrounding it with escaped double quotes resolved the issue.事实证明,问题在于完整宏文件路径中的空格,并且用转义的双引号将其括起来解决了这个问题。 TeraTerm just wasn't telling me that it wasn't finding the file. TeraTerm 只是没有告诉我它没有找到文件。 Should have been obvious, but I was sure it had been working previously when I was debugging, without requiring the quotes.应该很明显,但我确信它以前在调试时一直在工作,不需要引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM