Warning: I am no expert on building scripts, and sorry for lousy English.
In an case of generating a CSV from a database query I'm using the following commands.
CALL java.exe -classpath ... com.xigole.util.sql.Jisql -user dmfodbc -pf pwd.file -driver com.sybase.jdbc3.jdbc.SybDriver -cstring %constr% -c ; -input 42.sql -formatter csv -delimiter ; 2>>%LOGFILE% | CALL grep -v -e "SELECT right" -e "executing: " -e " rows affect" > %FicheiroR% 2>>%LOGFILE%
I'm using windows implementation of grep.
The 2>>%LOGFILE%
in both java and grep command is causing an error message indicating the file is being use by another process.
The Ugly workaround i have came up with is to put grep error redirect to a temporary %LOGFILE%.aux
java ... | grep ... 2>>%LOGFILE%.aux
type %LOGFILE%.aux >> % %LOGFILE%
del %LOGFILE%.aux
What is a better solution?
I wouldn't do this in java, use a scripting language like perl, powershell, vbscript (at least from an admin point of view). Any of these have excellent database interfaces under windows. My preference would be powershell. See this MS newsgroup post for an example of reading from a database in powershell.