I wrote a Tera Term macro to connect to a serial port, log the data coming in, and send a few test commands. If I run the macro manually from the local PC, everything works without an issue. I run the macro with ttpmacro.exe.
I use PsExec.exe to run some batch scripts on remote systems. When I try to run my Tera Term macro as part of those batch scripts, it hangs/freezes when it tries to connect. The macro just stops and does nothing. I know for sure that that is where it is hanging because I had the macro write to a file after ever command. If I remove the "connect" command from the Tera Term macro (my other commands stay in the macro) and instead connect with "ttermpro.exe /C=1 /BAUD=115200 /M=C:\path-to-macro\", it still hangs/freezes. The macro does not run and the serial port is not opened (If I remote desktop in after starting the remote script, I can open a PuTTY session to that serial port).
I apologize if that sounds confusing. I'll attempt to present a simplified example: On my remote system, I created four files, test_ttermpro.bat, test_ttermpro.ttl, test_ttpmacro.bat, and test_ttpmacro.ttl.
Contents of test_ttermpro.bat :
"C:\Program Files (x86)\teraterm\ttermpro.exe" /C=1 /BAUD=115200 /M=C:\Users\Public\test_ttermpro.ttl
Contents of test_ttermpro.ttl :
SessionLog='C:\Users\Public\'
strconcat SessionLog 'macrooutput_pro.txt'
fileopen sessionlogfile SessionLog 0 0
if sessionlogfile=-1 exit
;write to file to verify macro gets executed
filewriteln sessionlogfile '1'
disconnect
closett
exit
Contents of test_ttpmacro.bat :
"C:\Program Files (x86)\teraterm\ttpmacro.exe" C:\Users\Public\test_ttpmacro.ttl
Contents of test_ttpmacro.ttl :
SessionLog='C:\Users\Public\'
strconcat SessionLog 'macrooutput.txt'
fileopen sessionlogfile SessionLog 0 0
if sessionlogfile=-1 exit
filewriteln sessionlogfile '1'
ConnectString='/C=1 /BAUD=115200'
filewriteln sessionlogfile ConnectString
; Connect to serial port 1 at 115200 baud
connect ConnectString
disconnect
closett
exit
If I start the batch scripts while I am remotely logged into the remote system, from the remote system, they run without a problem. They open the COM port and each writes to its own session log file.
BUT, with those four files on the remote system, from my local system, I attempted to run:
psexec.exe /accepteula \\%REMOTE_SYSTEM% C:\Users\Public\test_ttermpro.bat
and
psexec.exe /accepteula \\%REMOTE_SYSTEM% C:\Users\Public\test_ttpmacro.bat
After executing each command (executed separately to test the different scripts), on the remote system I could see ttermpro.exe in the list of processes in Windows Task Manager, but I could open the COM port. test_ttermpro.bat never started its session log (macro never started). test_ttpmacro.bat did have a sessionlog, but just froze on the connect command. Neither exited until I ended the process via Windows Task Manager.
I am using Tera Term version 4.87.
Any ideas on why the "connect" command seems to hang/freeze when Tera Term is started remotely? Am I missing a command line parameter? Is there a better way to start Tera Term remotely and use a macro?
A usable solution using ttermpro.exe:
I changed test_ttermpro.bat to use the "/I" parameter. That .bat file now looks contains:
"C:\Program Files (x86)\teraterm\ttermpro.exe" /I /C=1 /BAUD=115200 /M=C:\Users\Public\test_ttermpro.ttl
Adding that parameter allows Tera Term to connect to the serial port, and read/write/log data when that .bat file is called remotely with Psexec.exe.