Say I have the following folder structure.
/foo
/bar1
code.do
/bar2
I want to run Stata on batch mode and have the log file generated inside /foo/bar2. What exact batch code should I run?
I'll give you examples that I tried and that didn't work. Right now the log file is being created as stata.log inside /foo. Also, I would like to run Stata on batch mode with -b, and not seeing the whole output on my GUI.
stata-se < "/foo/bar1/code.do" > "/foo/bar2"
stata-se "/foo/bar1/code.do" "/foo/bar2"
stata-se do "/foo/bar1/code.do" "/foo/bar2"
stata-se -b do "/foo/bar1/code.do" "/foo/bar2"
Both methods work for me. Below my exact terminal commands after creating your example directories:
Method 1
$ stata < /home/roberto/Desktop/foo/bar1/code.do > /home/roberto/Desktop/foo/bar2/code.log
Method 2
$ cd /home/roberto/Desktop/foo/bar2
$ stata -b /home/roberto/Desktop/foo/bar1/code.do
Notice that with Method 2, Stata will write the log file to the current directory. Just change it before running Stata.
Another option is to specify your log file inside of your do-file
log using /home/roberto/Desktop/foo/bar2/code.log, replace
Then you can run the file from batch mode without worrying about current directory
Related
I want to create a batch file that would:
1) change to a directory
2) run an executable command that is inside the directory
3) write the output of the execution to a text file
made use of cd to change directory but when i ran the executable command inside the directory it halts.
On code below, snmpset.exe is inside the SNMP folder
cd c:\Users\MyComputer\SNMP
START "c:\Users\MyComputer\SNMP\snmpset.exe -r:96.120.97.190 -c:hDaFHJG7 -o:1.3.6.1.4.1.1429.78.1.1001.1.0 -val:1 -tp:int" >> "c:\Users\MyComputer\list.txt"
If I ran the command by itself on the cmd line the result is this:
SnmpSet v1.01 - Copyright (C) 2009 SnmpSoft Company
[ More useful network tools on http://www.snmpsoft.com ]
OK
c:\Users\ralcal000\Downloads\SnmpSet>
Run the batch file in c:\Users\MyComputer\SNMP no need to change directory.
I need to set up a long list of temporary environment variables every time when I start a Python Flask app on Windows 10. Now I would like to create a batch file to run with all settings in one double click. The following lines run well if I copy them and paste to cmd prompt, but I couldn't run them in the batch file.
The execution of batch file always gets tripped and exited at the 2nd line venv\scripts\activate in the batch file, which has no issue at all if I copy and paste line by line at cmd.
cd C:\py\project
venv\scripts\activate
set env1=val1
set env2=val2
set FLASK_APP=some.py
flask run
One of the many (far too many) quirks of .bat files is that if you launch another .bat file, it doesn't know where to return to.
You need to explicitly call it:
call venv\scripts\activate
you can just use
start venv\Scripts\activate
This will open up a new terminal just like that... you can pass other commands using the && or & sign.
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.
I know the title doesn't make sense, but I have one question. I have made this file called Test.bin and here's whats inside the .bin file:
echo Hello World
Since its a test file, I've been trying to see if i can make a batch file that can read the commands in the .bin file and output it onto the console.
Not sure what you are trying to do exactly, but I think you have two options:
Rename test.bin as test.bat and run it with:
test
Start a new command interpreter and send it your commands:
cmd < test.bin
You could also use the copy command. However, for this to work the test.bin file should be
in the same directory/folder. Alternatively, you can specify the file's path.
Your code should look something like this:
#echo off
copy test.bin
Or, using the filepath method (pretending its on your desktop):
#echo off
copy C:/users/me/Desktop/test.bin
i have a batch file, b1.bat which internally starts another two batch files, b2.bat and b3.bat and b2.bat internall calls b4.bat and root batch file, b1.bat,waits until those three(b2,b3 and b4) finishes. In summary, scenario like this:
b1.bat -> b2.bat -> b4.bat
-> b3.bat
I want to write output of all 4 batch files(b1.bat, b2.bat, b3.bat and b4.bat) into single log file, my_log.txt. I want to do this with minimal effort ie., changing less no. of batch files as i have lot of batch files like this without logging. So i want to provide logging for them.
I) Is it possible to control the log file output from parent batch file ie.,b1.bat?
II) Do i need to change all batch files with redirection operator which writes the output to log file?
I could'nt find proper solution for this. Please suggest me in this regard.
Assuming you are NOT doing any asynchronous processing using START, you should be able to simply use:
b1.bat >my_log.txt
You might also want to capture error messages by appending 2>&1 to the command.