Optional Log File for Batch File? - user-interface

I have a Batch Interface I've created for a DOS program I'm using and I want to add an Option at the End to save the Output of the Batch File to a File, BUT I don't want the Log to be created unless the user says Yes at the END of the Batch File. So Far the Only way I've found to Optionally create a Log file is to Launch the Batch file like this "something.bat >output.txt" BUT that's at the Beginning BEFORE the Batch is even started which is NOT what I want. Any Ideas?

Write your log file to a temporary file, created below the %TEMP% folder. When you ask the user at the end of your program if he wants to keep it, copy your temporary file to the place where the user expects it. Otherwise remove the log file.

Related

Renaming file using WinSCP

I've created a file names upload.winscp with this content:
option batch abort
option confirm off
rename cinta.dmp cinta_bck.dmp
exit
which I call from a bat file with this content
winscp.com /script="E:\upload.winscp" /log="E:\upload.winscp.log"
but when I run the bat file, the file is not renamed, neither the log created
Your script does not open any connection (what is also the reason that no log file is created).
You are missing open command:
open ftp://username:password#example.com/
rename cinta.dmp cinta_bck.dmp
exit
Or you misunderstood the purpose of WinSCP.

Logging the exit of a batch file

So I wrote a tool with some batch commands, nothing specific. In the beginning the user can choose which task to perform thanks to a loop.
In that loop I included the "Q" option, as to quit the batch file. When this happens, it gets written to a logfile to check when the user started the script(s), and when it ended.
The issue is this only happens if the user actually quits/exits with Q. If (s)he quits by just closing the batch file, this won't be logged.
In short: how can I record when the user has quit the batch file without using the build-in function?
a batch file can't receive the "exiting"-event. What you can do is:
Make a launcher.bat file, that starts the original (yourfilename).bat file with:
start /wait (yourfilename).bat
the launcher.bat file will now wait until you close the second (yourfilename).bat file. place your log-information on the next line of launcher.bat
convert launcher.bat to launcher.exe using bat to exe converter (and make it invisible).

Is it possible to save and call data from an EXE file? Batch

So I have to make a program for secret stuff, and have to save the password in a file. Can i stock it directly into an EXE file from a batch file like:
echo pass=1234>password.exe
like if it was a batch file?
Because i don't want people to open this file and see the password.
Please be helpful and tell me where my mistake is, Thank you
this only works, if password.exe supports input via STDIN:
echo pass=1234|password.exe

Calling a batch file from another batch file in different directory - resources not found

I'm working with installshield and have a group of batch files that I want to run as part of the install process. Instead of executing each batch file from installshield I want to create one batch file that executes all of the batch files.
The issue I have is that the calling batch file sits two directories up from the others. When the batch file tries to call the others they fail to run because they can not find the resources that they need. It seems that when they are executed from the batch file two directories up they are for some reason using the relative path of the calling batch file. Is my assumption correct?
One of the batch files that I am calling is a batch file to star an h2 database the call looks like this:
call h2\bin\h2.bat
If I go to the /h2/bin directory in a command prompt the h2.bat runs fine but once I run it from the calling batch file this is the error that I get.
Error: Could not find or load main class org.h2.tools.Console
How do I call one batch file from another without using the calling batch files path?
Explanation
It seems that when they are executed from the batch file two
directories up they are for some reason using the relative path of the
calling batch file. Is my assumption correct?
Yes your assumption is correct. Calling a batch file will not change the current working directory. The main batch file will be found because you are providing the correct relative path, but all the other relative paths will be seen from the perspective of your current working directory, not from the directory that contains the main batch file.
%~dp0 is your friend, it yields the drive letter and path to the batch file containing that character sequence. Use it as a basis for relative paths and your batch files will work no matter who calls them from where.
Example:
Fictitious h2.bat that won't work:
#echo off
h2.exe start
Working h2.bat:
#echo off
"%~dp0\h2.exe" start
See What does %~dp0 mean, and how does it work? for more explanations on %~dp0
Try setting the directory:
cd ht\bin\
call h2.bat
cd %HOMEPATH%
REM just reset to where ever you were before.
If that doesn't work, try using the C:// prefix in your path. That might/might not work.
Good Luck!
Suppose current .bat file is running in C drive and you want to run .bat file placed in D: directory then in first .bat write.
D:
cd "D:/folder/folder2/"
call batFile.bat
It might be because you don't have permission. M facing the same problem and i found the solution like this -
Right click on your task than properties.
In properties click on General tab and then click on 'User Group or User' and select appropriate user.
Or create a another bat file to call your bat file and schedule that file. you can create the bat file like this -
open Notepad and give your original bat file path and then call bat file with name like -
D:
cd "E:/ABC/FirstJob/main/"
call main_run.bat
Now save this file with .bat extension.
if your bat file is correct, try cmd command as below and hit enter(tried in windows 10):
"\h2.bat"
e.g: "C:\Users..\bin\h2.bat"
I tried :
pushd h2\bin\
call h2.bat
=> It 's okay.

Windows .bat file doesn't execute its sequence

I created a simple install.bat file into my application folder, to execute its thing on windows.
But it only executes the first line of the .bat file.
Is there something that I need to add so it continues after the first one is done?
copy something somewhere
move something somewhereelse
gem install etc
Above are the type of commands that are in the .bat.
Do I need to anything something inbetween?
Is the first command in your batch file actually a copy command, or is it a command that's running another batch file?
Running a batch file from another by simply using the second batch file;s name will not return to the calling batch file.
If you want one batch file to invoke another and return you have to use the call command.
Are you overwriting a file? If so you'll need to add the /Y to the copy command to supress the prompt that asks if you want to overwrite the file.
Use the /h parameter to get help on the copy command. It will show this usage and some others.
As written above, all three lines will execute. I imagine that the second and third lines are failing. You should capture the output which will explain why those lines failed.

Resources