Good day guys.
Currently, I am developing a code to execute a Teraterm macro which I had saved as a *.ttl file. The name of the file is "new.ttl" and the content is as below:
showtt 0
filedelete 'a.txt'
pause 5
:Close
closett
So, the logic is just to delete "a.txt" file, wait for 5 seconds and close Teraterm. This new.ttl works perfectly when I run it manually using Teraterm, where I load the macro in the tab control>macro. This simple .ttl file is just for some trial for me before I start to write a more complex code.
Now, I tried to launch the .ttl file using C#. The code is as below:
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();
}
}
}
The execution runs without any error, but, the result is not as expected. After the execution, I can see "a.txt" is still inside the mentioned path as in the code. I am not sure where I went wrong. This is just a starting step for me before I develop a more complex .ttl file and execute it through c#.
Your help is deeply appreciated. Thank you very much.
Good day guys,
After 2 days of struggle, I managed to get the answer.
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();
}
}
}
The version of Teraterm that i am currently using is 4.94 and I had also installed TTLEditor version 1.5 to create the .TTL file. It seems that the problem was,
1) To execute a .TTL file programmatically from C#, I need to place the .TTL file in the same folder where TTPMACRO.EXE and TTERMPRO.EXE is located in my system. This is shown by the string value ttlpath in my code.
2) In the ttlpath, the string value @"TTPMACRO" need to be added to the folder as this will make the .TTL file to be executable.
And, for your info, in my system, the text file a.txt that will be deleted if the logic of the .TTL file is executed is located at: C:\Users\Admin\AppData\Local\VirtualStore\Program Files (x86)\teraterm
For more info on how to run teraterm macro files, refer to this link; https://ttssh2.osdn.jp/manual/en/macro/howtorun.html
have a nice day..
Hari