美好的一天。
当前,我正在开发一个代码来执行我保存为 *.ttl文件的teraterm宏。该文件的名称为" new.ttl",内容如下:
Showtt 0
filedelete'A.txt'
暂停5
:关闭
collett
因此,逻辑只是要删除" a.txt"文件,等待5秒钟并关闭Teraterm。当我使用teraterm手动运行它时,此新的.ttl可以很好地工作,在该teraterm将宏加载到选项卡控件>宏观中。这个简单的.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:TeraTermConnectTeraTermConnect";
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#执行C#之前,这只是我的开始步骤。
您的帮助深表感谢。非常感谢。
美好的一天,
经过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 local virtualstore program文件(x86) teraterm
有关如何运行teraterm宏观文件的更多信息,请参阅此链接;https://ttssh2.osdn.jp/manual/en/macro/howtorun.html
祝您有美好的一天..
hari