batch

How to Tell FORFILES to Execute Command on Path?

I'm missing something (obvious?) about escaping my strings or spaces in the following Windows Server 2k3 batch command. FORFILES -m *.wsp -c "CMD /C C:\Program^ Files\Common^ Files\Microsoft^ Shared\web^ server^ extensions\12\bin\stsadm.exe^ -o^ addsolution^ -filename^ @FILE" Results in the following error 'C:\Program Files\Common...

Is there a way in a batch script to keep the console open only if invoked from Windows Manager?

I have a DOS batch script that invokes a java application which interacts with the user through the console UI. For the sake of argument, let's call it runapp.bat and its contents be java com.example.myApp If the batch script is invoked in a console, everything works fine. However, if the script is invoked from the Window Manager, the...

How to append filename to current directory in Batch file?

Hi, I want to search a file in the current directory from which the batch is running, append the filename to the directory and include that entire directory as part of command that. So..... Directory: C:\tempfiles\batch Files in C:\tempfiles\batch tmp1.txt tmp2.txt tmp3.txt anyname.exe I want the batch file, run from the directory, ...

Is it possible to add a directory to DLL search path from a batch file or cmd script?

MSDN says that the function SetDllDirectory() can be used to insert a directory into the DLL Search Path. Can this function be accessed from a batch file or cmd script, perhaps using via cscript? The aim is to have our development version of a dll found before a pre-existing older one in %WINDIR% etc. without having to write a program j...

CMD.EXE batch script to display last 10 lines from a txt file.

Any ideas how to echo or type the last 10 lines of a txt file? I'm running a server change log script to prompt admins to state what they're doing, so we can track changes. I'm trying to get the script to show the last 10 entries or so to give an idea of what's been happening recently. I've found a script that deals with the last line, ...

Batch deletion / purging of records via Java ORM

Right - I want to delete (e.g.) 1,000,000 records from a database. This takes a long time -> the transaction times out and fails. So - I delete them in batches say 25000 records per transaction. Using the limit clause on MySQL or ROWNUM on Oracle. Great this works. I want to do this in a database indepedent way. And from an existing Jav...

Dealing with quotes in Windows batch scripts

In a Windows batch file, when you do the following: set myvar="c:\my music & videos" the variable myvar is stored with the quotes included. Honestly I find that very stupid. The quotes are just to tell where the string begins and ends, not to be stored as part of the value itself. How can I prevent this from happening? Thanks. ...

Command line to recursively delete files but excluding a certain file

I need to delete files of a certain type (.zip files, say) from a folder, and all of its sub-folders, using the command line. Ideally I am looking for something that can be run as a .bat file in Windows. I know there is a /S switch for the DEL command to look in sub-folders, but to add to the challenge I need to exclude files of a cert...

Separating data from a constantly appended file into a new file

I am using a macro to export a table in a Microsoft Access database to a csv file in order to import into a mysql database. I ended up using a batchfile that would place a marker in the text file before the exporting took place, and then place everything after the last marker into a new file. This works fine, except for the fact that acc...

Batch Script to read each line of text file and return a value?

I want to write a batch script that should read a text file line by line and search for a keyword. If the keyword is found it should return value 0 else it should return 1. Like this it should keep on incrementing the value until the end of the file. The output should go to a file. The sample log is as follows, Website is available HT...

problem reading args from batch script

On windows, I'm trying to acquire the file name using the %~f1 parameter. I'm doing this from a new voice (command) which I've added to the contextual menu. In the windows registry, the voice simply calls a batch script which prints the file name, by this way: `C:\script.bat %~f1` but I get this output: `C:\Documents and Setting...

"Bring to front" for Windows XP command shell

Is there a command I can put into a Windows XP .bat file to bring the command shell to the front? ...

How to stop batch script on del failure

We have a batch script that removes files (del) and directories (rd). Does anyone know how to halt (fail) execution of the script if any of these delete statements fail? They could fail if a file/directory is locked by Windows. Thanks. Update Statements I'm using: Del: del *.* /S /Q RD: FOR /D %%G in (*) DO RD /s /q %%G ...

Escaping Double Quotes in Batch Script

How would I go about replacing all of the double quotes in my batch file's parameters with escaped double quotes? This is my current batch file, which expands all of its command line parameters inside the string: @echo off call bash --verbose -c "g++-linux-4.1 %*" It then uses that string to make a call to Cygwin's bash, executing a L...

DOS choice command on xp/NT

Is there a way to prompt users for input (ie: Yes/No) from a Dos batch script that works on XP and Windows 2003 server? It seems some commands (ie: choice) only work on one OS and not others. ...

odd .bat file behavior

I have a bat file with the following contents: set logfile= D:\log.txt java com.stuff.MyClass %1 %2 %3 >> %logfile% when I run the bat file though, I get the following: C:\>set logfile= D:\log.txt C:\>java com.stuff.MyClass <val of %1> <val of %2> <val of %3> 1>>D:\log.txt The parameter is incorrect. I'm almost positive the "...

How to include pipe character in an argument to a batch file from a bash script?

I have a shell script that I want to execute this line: qtvars.bat vsstart "qt.sln" /BUILD "Debug|Win32" This works fine (though I had to modify qtvars.bat, but that's beside the point). The problem is that I want the command to execute to be in a variable: EDIT: This doesn't work either, if I type it into bash. Previously I was typin...

Creating folder using bat file

I need to write a bat file which creates a new folder using current date and time for folder name. I came up with the following: for /f "tokens=1-3 delims=:," %%i in ("%TIME%") do md %DATE%-%%i.%%j.%%k Does this code has any flaws? Is there an easier / more natural way to do it? ...

How to Prevent SQL Injection in Oracle SQLPlus?

Obviously if I am using JDBC/ODBC, I can use bind variables and prepared statements to prevent SQL injection. However, when data is passed to batch processes that end up invoking Oracle SQLPlus, is there a way to prevent SQL injection? For example: query.sql: select '&1' from dual; exit; If I call this script from SQLPlus thusly: $ ...

How do I pass arguments to shell script?

I have a batch file like this: java temptable %1 %2 I need the equivalent shell script for the above. I will pass the arguments to the shell script and that should be passed to temptable. ...