output batch file log to seperate directory - batch-file

I have a batch file which currently output a log file by calling its extension
(sqlplus #Down.sql "test" "testl") > "%~dpn0.log"
which outputs the log file to the same location of the batch folder.
e.g. C:\Folder1\run.bat
of course, the log file would be run.log
I would like to output the log file to a log folder.
similar to C:\Folder1\log\run.log.
Anyhelp is appreciated in pointing out hwo to do it in my source code. Thanks

...> "c:\folder1\log\%~n0.log"
should suffice. The trick is the %0 means the name of the batch, and this can be mofified by ~letters which may be used in any combination.
The letters that are significant are listed conveniently in the for documentation, accessible from
for /?
executed from the prompt.

Related

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)

Doing a batch file for first time

First time doing batch files, I don't even know how to do it. I need a batch file that given a path (say I:\FOLDER1\SUBFOLDER1\) will produce a text file showing all the subfolders in that directory as fully qualified paths.
Something like this:
I:\FOLDER1\SUBFOLDER1\SUBSUBFOLDER1
I:\FOLDER1\SUBFOLDER1\SUBSUBFOLDER2
I:\FOLDER1\SUBFOLDER1\SUBSUBFOLDER3
I:\FOLDER1\SUBFOLDER1\SUBSUBFOLDER4
...
If understand you are trying to list file path
dir/s/b *.txt
to redirect it into a text file
dir/s/b *.txt > textfile.txt
Help full Link

Loading .BAT for Multiple Subfolders

I have a problem : I have a .bat file that makes loading a database, however , he can only do this when copied to the same folder where the database . As I have multiple databases in various subfolders in a folder "Data", I am copying the .bat for all subfolders . This is really need ? How can I make the .bat function independently of folders?
It's extremely unlikely that your database-creation batch file needs to be in the same directory as your database-to-be, but it;s not impossible.
Try
pushd "?:\wherever\your\database\needs\to\be\created"
call "?:\wherever\your\database\creation\executable\resides\database_creation_batch_name.bat"
popd
This should work.
If it does, then what you need to do is to place the database-creation batch "on the path".
from the prompt, execute path
This will show a semicolon-separated list of directories. Simply copy the .bat file to any one of them, and thereafter
database_creation_batch_name
will create your database in the current directory. Note that within a batch file, you would need to execute call database_creation_batch_name.
If that doesn't work, then post a relevant sample of the batch here for analysis by editing it into your initial post.
You can pass a command-line argument which specifies the path you want the batch script to operate in. Google for "batch file arguments".

Execute .exe from a batch file

In an application folder, there are n number of files. The application exe name "ClearMongoDb.exe" take some parameter like dbname.
ex: clearMongoDb.exe -db "SynchoMeshDB"
I am stuck with below :
I want to execute the exe from a batch file with same parameters
the batch file will be placed in the same application folder.
user can copy the application folder to any location
If user double clicks on the .bat file the exe should start working.
User should not be required to make any changes in .bat file
If the batch file is in the same folder as the executable, then you can do like this:
clearMongoDb.exe -db "SynchoMeshDB"
Just add this line in your batch file. Now the refference is in the same folder as the executable, no matter where the ENTIRE folder is moved (or at least the executable and batch file).
update:
As foxidrive mentioned, in order to see the output, place a PAUSE command at the end. So, your batch file should be like this:
clearMongoDb.exe -db "SynchoMeshDB"
PAUSE
If you just want to pass all the parameters given to a batch file to an EXE called from that batch file, use %*.
foo.exe %*
How do I pass command line parameters to a batch file?
You can just use a shortcut to the file and add the parameters on the path. no need for an extra batch file.
edit: unless you want to pass the batch file parameters to the .exe, as some people read this. what do you want to do? execute a .exe with the same parameters each time, or pass the .bat parameters to the .exe?

Executing .bat file in FOR loop

Edit: Brief Summary
I have number files in a directory, called crash0, crash1 etc. I want to run a .bat file for each of this with a command line like:
abc.bat crash0 > crash0.txt
How can I make another .bat file that loops over all the crashXX files calls abc.bat once for each one of them?
Original Question
Please find my situation below..
I have some files (number may vary each time) in a folder with its name starting with crash. That is crash0, crash1..etc. I want to provide these files as an input to a .bat file (let it be abc.bat) and then navigate the out put a corresponding text file. The command looks like abc.bat crash0 > crash0.txt. I have to do this to all the crash files in the folder. This abc.bat files actually converts the non-readable files to a readable format. So at the end I should have txt files like crash0.txt, crash1.txt.. etc for the corresponding crash files which i provided as the input. Can any one help with a .bat script to run this in cmd?? am new to .bat scripting.. thx in advance
for %%i in (crash*) do #call abc.bat %%i > %%i.txt

Resources