使用C#

时间:2017-03-07 07:48:29

标签: c# teraterm

美好的一天。

目前,我正在开发一个代码来执行我保存为* .ttl文件的Teraterm宏。该文件的名称是" new.ttl"内容如下:

showtt 0

filedelete' a.txt'

暂停5

:关闭

closett

所以,逻辑只是删除​​" a.txt"文件,等待5秒钟并关闭Teraterm。当我使用Teraterm手动运行它时,这个new.ttl工作得很好,我在选项卡控件>宏中加载宏。在我开始编写更复杂的代码之前,这个简单的.ttl文件仅供我进行一些试用。

现在,我尝试使用C#启动.ttl文件。代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;
using System.Diagnostics;

namespace TeraTermConnect
{
    class Program
    {
        static void Main(string[] args)
        {
            //Declare process for .ttl
            Process process = new Process();
            ProcessStartInfo start = new ProcessStartInfo();

            //variables
            string ttlpath = @"C:\TeraTermConnect\TeraTermConnect";
            string ttl = "new.ttl";
            string ttpHidden = @"/V";

            //start the .ttl file
            start.FileName = ttlpath;
            start.Arguments = ttpHidden + ttl;
            start.UseShellExecute = false;            

            //Tried a lot of thing here, not sure how to run the .ttl
            Process.Start(start);

            Thread.Sleep(5000);

            Console.WriteLine("The process is over");
            Console.WriteLine();
            Console.WriteLine("Check the text file...");
            Console.WriteLine();
            Console.WriteLine("Hit enter to exit...");
            Console.ReadKey();
        }
    }
}

执行没有任何错误,但结果不符合预期。执行完毕后,我可以看到" a.txt"仍然在代码中提到的路径内。我不知道我哪里出错了。在我开发一个更复杂的.ttl文件并通过c#执行它之前,这只是我的一个开始步骤。

非常感谢您的帮助。非常感谢你。

1 个答案:

答案 0 :(得分:0)

美好的一天,

经过2天的奋斗,我找到了答案。

using System;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;

namespace TeraTermConnect
{
    class Program
    {
        static void Main(string[] args)
        {
            //Declare process for .ttl
            Process process = new Process();
            ProcessStartInfo start = new ProcessStartInfo();

            //variables
            string ttlpath = @"C:\Program Files (x86)\teraterm\" + @"TTPMACRO";
            string ttl = "new.ttl";
            string ttpHidden = @"/V ";
            ProcessStartInfo start = new ProcessStartInfo();

            //start the .ttl file
            start.FileName = ttlpath;
            start.Arguments = ttpHidden + ttl;
            start.UseShellExecute = false;            

            process.StartInfo = start;

            try
            {
                Process.Start(start);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Console.WriteLine("The process is over");
            Console.WriteLine();
            Console.WriteLine("Check the text file...");
            Console.WriteLine();
            Console.WriteLine("Hit enter to exit...");
            Console.ReadKey();
        }
    }
}

我目前使用的Teraterm版本是4.94,我还安装了TTLEditor 1.5版来创建.TTL文件。似乎问题是,

1)要以编程方式从C#执行.TTL文件,我需要将.TTL文件放在TTPMACRO.EXE和TTERMPRO.EXE所在系统中的同一文件夹中。这由我的代码中的字符串值ttlpath显示。

2)在ttlpath中,字符串值为@" TTPMACRO"需要添加到文件夹中,因为这将使.TTL文件可执行。

并且,对于您的信息,在我的系统中,如果执行.TTL文件的逻辑,将删除的文本文件a.txt位于: C:\ Users \ Admin \ AppData \ Local \ VirtualStore \ Program Files(x86)\ teraterm

有关如何运行teraterm宏文件的更多信息,请参阅此链接; https://ttssh2.osdn.jp/manual/en/macro/howtorun.html

度过美好的一天..

相关问题