伙计们,日安。
目前,我正在开发一个代码来执行Teraterm宏,我已经将该宏保存为*.ttl文件。文件名为"new.ttl“,内容如下:
阵雨0
文件“a.txt”
暂停5
*关闭
衣橱
因此,逻辑就是删除"a.txt“文件,等待5秒并关闭Teraterm。当我使用Teraterm手动运行它时,这个new.ttl工作得很好,在那里,我在选项卡control>macro中加载宏。在我开始编写更复杂的代码之前,这个简单的.ttl文件只是对我进行一些尝试。
现在,我尝试使用.ttl启动C#文件。守则如下:
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#执行它之前,这只是我的第一步。
我们对你的帮助深表感谢。非常感谢。
发布于 2017-03-09 04:52:17
伙计们,今天好,
经过两天的挣扎,我终于得到了答案。
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)要从.TTL中以编程方式执行C#文件,我需要将.TTL文件放在系统中TTPMACRO.EXE和TTERMPRO.EXE所在的文件夹中。这由代码中的字符串值ttlpath显示。
2)在ttlpath中,需要将字符串值@"TTPMACRO“添加到文件夹中,因为这将使.TTL文件成为可执行文件。
另外,在我的系统中,如果执行C:\Users\Admin\AppData\Local\VirtualStore\Program文件的逻辑,将删除的文本文件a.txt位于:.TTL文件(x86)\teraterm
有关如何运行teraterm宏文件的更多信息,请参阅以下链接:https://ttssh2.osdn.jp/manual/en/macro/howtorun.html
祝你今天愉快..。
哈里
https://stackoverflow.com/questions/42642909
复制相似问题