0

I need to save the data of a java program into a file. The problem is, it returns a "The filename, directory name, or volume label syntax is incorrect" error when I add the %DATE% and %TIME% variables into the filename. Without the date time variables it works fine.

As well I need to output the result into the console and the file. As far as I have seen, there is no direct possibility to do so. Workaround: I'm just reading the file again into the console. When doing that with the date time variable, I get the same error.

set datetime="%DATE%-%TIME%"

java -Xmx1024m -jar org.hl7.fhir.validator.jar generated.json  -version 4.0.1 -ig hl7.fhir.uv.livd > "errlog/%datetime%.log"

type "%CD%\errlog\%datetime%.log"

I never write batch files so could be a very "stupid" problem. Thanks in advance!

  • `%DATE%` has `/` (slashes) in it, which are not valid in a filename. You need to replace the slashes with another character. – abelenky Jan 28 '20 at 13:42
  • Yeah i just realized that too. I have an european format with "hh:mm:ss.ms" and ":" are not allowed. Thanks!! – Eldar Omerovic Jan 28 '20 at 13:46

1 Answers1

1

Try this line instead:

set datetime="%DATE:/=-%-%TIME::=_%"
abelenky
  • 63,815
  • 23
  • 109
  • 159