Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Not sure any more of what was appening, but i suspect probably the problem could be solved by using 2>>&1 that redirects standard error to standard output. – jpmartins Apr 14 '12 at 1:10

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.