I am trying to create a batch file that works something like a watcher, here is what I am trying to do:
The batch keeps monitoring a .txt file for any modification.
Once the file has been modified by any reason, the batch file proceeds with its function.
The function can vary, either change/replace/delete a line of text inside the file or replace the actual .txt file with a previous clone of it.
After this it keeps monitoring, the cycle repeats itself to prevent the file from being modified.
I do not understand anything of batch, I have tried to find guides and ways of doing it but I am really confused so if anyone could help me with this (a guide explaining how to or the actual final batch) I would be very grateful.
Thank you for your time and patience!
Batch file article on Wikipedia will give you enough information to start understanding batch files.
There is a basic example with explanation that will be helpful getting started with running batch file.
Also take a look at the resources mentioned at the Stack Overflow Batch tag info
Once you know how to write batch files, look for commands that you will require to complete your task.
Related
I need to check the files of a versioned system. To do that, I need to write a batcha program so to compare the contents of several folders containing the repositories.
So, my question is: how can I "read" the names of all the subfolders inside a folder, so to use these names later to find subfolders having the same names in a different repositories?
I suppose I may use DIR to print on the screen a list of these names but I don't know how to write it on a text file and then read it. Moreover, I should edit this kind of list, anyway.
Any suggestions or new ideas to solve this problem?
I thank gratefully who ever will answer.
it seems that you can get the subfolders using batch file from perl as follows:
system("start C:\\Temp\\mybatchfile.bat");
or you might try to pass your command suggested by #Stephan straight to system and try to handle what it is returned.
I have created a batch file with 2000 lines of code and which will peroform various operations in my daily work. For this batch file I have to give some inputs to enable/disable some of the operations. Finally the batch file is ready and working fine.
But I want to have a log file in which everything which is coming on the command window should be logged, including the inputs that I have given to the batch file and also the execution process.
Is there any way do like this? Any one of you can help me?
Thanks in advance...
Nagaraju
You are not telling how you are invoking the batch file. You could try adding redirection to the command line (batchfile.bat > filename.log), although that won't catch whatever you type in as input. You could, however, change the script to print out the input parameters so that they could be caught in the log file.
I can find plenty of answers on the internet about how to open a specific file, e.g. http://answers.yahoo.com/question/index?qid=20080102230630AAfu5dF
However, I need to provide a way of opening a non-specific file in a program called by a batch file.
To explain, here is an example. The user has a folder with 100 files in with the .xyz extension. He wants to be able to double click on ANY file and open it in his "XYZ Viewer," but to run his XYZ Viewer he needs to run a batch file that alters his registry and then runs the actual XYZ Viewer .exe.
If you select the batch file to be the default program via the "Always use the selected program to open this kind of file" tickbox, it will open the program, but without using the standard Windows function of opening the file that instigating the running of the program.
Is there a way to run the program through the batch file and for it to both run the program and open whichever file it was that instigated the running of the program?
I suspect this is impossible, but any suggestions would be very gratefully received!
Cheers.
Edit:
The program does eventually support opening a file placed as an argument to it.
My code is
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe
Does the program eventually support opening a file placed as an argument to it? In the example you linked, mspaint opens the first parameter given to it.
If your batch file isn't currently doing this, you will have to edit it to contain the batch parameter(s).
See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true for some fuller documentation on it.
Essentially you want to add %1 somewhere like:
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe %1
OK so I tried to convert bat to exe using many programs but at the end all of them just put the bat files in temp folder so I wonder if there is another way to protect the code
I thought is there a way to delete that bat from the temp folder after executing the exe file ?
I even thought is there a way to make the exe to put the temp bat in memory ? I heard that its possible but I don't how to do this
any Idea
I want this because I gave a sample exe(that di half the work) file to a client to test it and then pay for a program that I put a lot of hours on it , but after 2 days he answerd me that he isn't interested so I think that he did get he source code
After a bit of searching I found this which is a batch script that uses 7-Zip to compile the batch into an exe. It will still dump it out into %temp% but it does say that it removes all the temporary files once it has finished, which you said you would like.
You other option would be to re-write the code in a proper programming language like C or C++. Although it might not be impossible to decompile the code I don't think anyone would bother trying!
You can also make it delete itself after it is done.
See this answer to How to make .BAT file delete it self after completion?
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.