How to Log Teraterm into Text file by using Batch File - batch-file

I am using Ttermpro.exe to run TTL file. After that, teraterm will display all the output. I want to insert the display in teraterm into logfile.txt by using batch file command. Any idea on how to resolve this problem?
"C:\Program Files (x86)\teraterm\ttermpro.exe" /L=C:\0465\PCU 90000465\UartLog.txt "C:\0465\PCU 90000465\COM.TTL"

I don't know if this answers your problem directly, but based on what I think you're saying, try:
In the teraterm ttl file, include this to avoid the logging command in TTermPro:
logopen 'C:\0465\PCU 90000465\UartLog.log' <binary flag> <append flag>
... more content
... and when done
logclose
The binary flag and append flag can both be set to zero, but you can find more info here: https://ttssh2.osdn.jp/manual/en/macro/command/logopen.html
Generally, I thought the log file was a .log extension, but if you really want it to become a .txt file, you could also add after the logclose function
filerename 'C:\0465\PCU 90000465\UartLog.log' 'C:\0465\PCU 90000465\UartLog.txt'
As far as the batch file goes, you'd simply change directories to the teraterm TTermPro executable and then run the command to execute the macro.
cd C:\Program Files\teraterm
TTERMPRO /M="C:\0465\PCU 90000465\COM.TTL"
but you can also achieve the same thing just using the TTPMacro as
cd C:\Program Files\teraterm
TTPMacro /M=C:\0465\PCU 90000465\COM.TTL
Just save one of those two sets of commands as a .bat file and that should hopefully work.

Related

How to run Teraterm and TTL file using Batch file?

From Tera Term. To start MACRO (TTL), select the [Control] Macro command and then the macro file in the Open Macro dialog box.
The question is how to write command inside batch file, to call macro file and run automatically by just opening batch file.
This is the command from previous post.
"C:\Program Files (x86)\teraterm\ttermpro.exe" /I /C=1 /BAUD=115200 /M=C:\Users\Public\test_ttermpro.ttl
From my uderstanding, /M should be command to open macro file. But now, Teraterm is open but don't execute TTL file. Any idea on how to solve this issue?
Here the solution for my question. I create a batch file to execute ttpmacro.exe and .TTL file.
#echo on
start "C:\Program Files (x86)\teraterm\ttpmacro.exe" "C:\PCU_BOOTLOADER.TTL"
cls
File location might be different. Baudrate and COM port are set inside TTL file.
I don't know why that isn't working but maybe try:
cd C:\Program Files (x86)\teraterm
TTERMPRO /I /C=1 /BAUD=115200 /M="C:\Users\Public\test_ttermpro.ttl"
I believe using TTERMPRO, the path to the Macro must be in quotations
Personally, I'd utilize the TTPMacro.exe for this function and define the connection type and baudrate within the ttl, unless there is a reason they might change between executions of the TTL.
Doing it that way, within the .ttl script add near the beginning or where applicable:
connect '/C=1'
setspeed 115200
That will define the com port and baud rate of the connection
In the batch file:
cd C:\Program Files (x86)\teraterm
TTPMacro /I C:\Users\Public\test_ttermpro.ttl

Why does my IrfanView command not work on batch file but work when typing directly in CMD?

I'm a first-day user of IrfanView and have a question. I have a bunch of multi-page tiff files and I want to split all of them individually. So I write a batch file with the command like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename2.tif /extract=(D:\newdirectory,tif)
...and so on...
I put the batch file on D drive, let's say in folder "batchfolder". But it can't do the job, this message shows up for each unsuccessful case (all of them were unsuccessful):
D:\batchfolder>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I guess that has something to do with the batch file location, so I bring it to C drive. But still it can't run properly, this time a different message shows up:
C:\>C:\Program Files\IrfanView D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif) 1>i_view64.exe
Access is denied.
This C:\>C:\ makes me think maybe the C:\ part on the batch file was redundant. So I take it out to make it look like this:
Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
...
But it doesn't work, either with the batch file on D or C drive.
I then try to type it directly in the CMD window and it works normally, like this:
C:\Program Files\IrfanView>i_view64.exe D:\originaldirectory\filename1.tif /extract=(D:\newdirectory,tif)
Can you tell where my batch file goes wrong?
This is another question. Typing (or copy and paste) the batch file contents into the CMD works OK. But upon successful splitting, the original, multi-image file automatically opens. How can I deactivate this feature?
Note: Cross-post here: https://irfanview-forum.de/showthread.php?t=11150&p=47111#post47111. Hope it doesn't violate policy.
enclose paths/filenames with spaces into quotes to tell the interpreter, it's not two words, but one string (or even better: get used to always enclose path/filenames):
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)`
Before you build a batchfile with dozends or hundreds of nearly identical lines, use a for loop to process all .tif files in the folder:
#echo off
for %%a in ("D:\originaldirectory\*.tif") do (
"C:\Program Files\IrfanView\i_view64.exe" "%%~fa" /extract=("D:\newdirectory",tif)
)
see for /? for more information.
You need to call the executable with quotes in the batch. Also, the > in the path will not work either. Also consider using a for loop instead of creating single batch lines.
Please try this:
"C:\Program Files\IrfanView\i_view64.exe" "D:\originaldirectory\filename1.tif" /extract=("D:\newdirectory",tif)

Batch Files - Closing Opened Text Files

I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.

How put path changing .bat file inside %PATH%?

I have a problem described here (you can read it for better understanding). I need to write .bat file that change path.
For example:
While sending a command in cmd: cd ~
I want to go to %HOMEPATH%. In fact - I just want to replace ~ by %HOMEPATH% in every command which include directories.
How can I achieve it? I read here that I must to put path changing .bat file inside %PATH%. How to do it? And how to code that path changing function in Windows scripting language?
Any advice would be appreciated ;)
setx path %path%;path\to\folder\file\is\in
set ~=%homepath%
cd %~%
this should work... close enough?

How to mention C:\Program Files in batchfile

I need to invoke an exe file in C:\Program Files directory from a batch file.How can we mention the directory name "Program Files" in batch file.I am getting error like C:\Program not found.
I believe that % or ~ needs to be added in between but couldn't get it.Kindly assist.
Surround the script call with "", generally it's good practices to do so with filepath.
"C:\Program Files"
Although for this particular name you probably should use environment variable like this :
"%ProgramFiles%\batch.cmd"
or for 32 bits program on 64 bit windows :
"%ProgramFiles(x86)%\batch.cmd"
On my pc I need to do the following:
#echo off
start C:\"Program Files (x86)\VirtualDJ\virtualdj_pro.exe"
start C:\toolbetech\TBETECH\"Your Toolbar.exe"
exit
Now that bash is out for windows 10, if you want to access program files from bash, you can do it like so: cd /mnt/c/Program\ Files.
I use in my batch files - c:\progra~2\ instead of C:\Program Files (x86)\ and it works.
I had a similar issue as you, although I was trying to use start to open Chrome and using the file path. I used only start chrome.exe and it opened just fine. You may want to try to do the same with exe file. Using the file path may be unnecessary.
Here are some examples (using the file name you gave in a comment on another answer):
Instead of C:\Program^ Files\temp.exe you can try temp.exe.
Instead of start C:\Program^ Files\temp.exe you can try start
temp.exe
use this as somethink
"C:/Program Files (x86)/Nox/bin/nox_adb" install -r app.apk
where
"path_to_executable" commands_argument
Interestingly with variables ,this worked for me ...
SET "VESTADIR=\\%TARGET%\C$\"Program Files (x86)"\Cassidian\VESTA"
While createting the bat file, you can easly avoid the space. If you want to mentioned "program files "folder in batch file.
Do following steps:
1. Type c: then press enter
2. cd program files
3. cd "choose your own folder name"
then continue as you wish.
This way you can create batch file and you can mention program files folder.

Resources