0

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?

MattB
  • 11,124
  • 1
  • 29
  • 36
jpmartins
  • 1,334
  • 2
  • 11
  • 14
  • 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 01:10

1 Answers1

1

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.

Jim B
  • 23,938
  • 4
  • 35
  • 58