Tiggyboo
Tiggyboo

Reputation: 562

Windows Paths only disfunctional in batch context

I have a batch file that builds a path, then cannot find the path. Although if I try the exact same path from the command line, it works. Here's some clunky code to illustrate my issue:

C:\batch>SET JAVA="I:\"
C:\batch>SET JAVA-LOCAL="J:\raw\java\"
C:\batch>SET CF005="V:\"
C:\batch>SET CF006="U:\"
C:\batch>SET CF005-local="J:\raw\cf\005\"
C:\batch>SET CF006-local="J:\raw\cf\006\"
C:\batch>SET CF-local="J:\raw\cf\"
C:\batch>SET REPORTS="J:\"
C:\batch>c:\cygwin\bin\grep -v "#" %CF006-local%ex%IISDT%.log > %CF-local%ex%IISDT%-temp.log

/usr/bin/grep: J:\raw\cf\006\ex150209.log : No such file or directory

C:\batch>ls J:\raw\cf\006\ex150209.log
J:\raw\cf\006\ex150209.log

So you can see that the file can't be found initially, but when I reference it from the command line with 'ls', it seems suddenly available. Thanks in advance!

Upvotes: 0

Views: 58

Answers (1)

JosefZ
JosefZ

Reputation: 30103

Don't know your definition of %IISDT% but the %CF006-local%ex results to "J:\raw\cf\006\"ex; analogously %CF-local%ex results to "J:\raw\cf\"ex. Cannot become a valid base for a file name.

Your set commands should look as follows rather:

SET "JAVA=I:\"
SET "JAVA-LOCAL=J:\raw\java\"
SET "CF005=V:\"
:: and so on...

Edit: for debugging purposes

  • use set without parameters to show environment variables;
  • consider prefixing your own defined ones e.g. with _ underscore: then set _ shows those only;
  • in a batch script, use echo on

An echo example (note ^ escaped > redirector for echo only):

echo -v "#" %CF006-local%ex%IISDT%.log ^> %CF-local%ex%IISDT%-temp.log

Resource:

Upvotes: 1

Related Questions