cmd.exe command line string limits

2019-04-13 09:51发布

I've been working on spooling a bat file from a oracle query that would copy contents from one location to another,

Now that command that are getting generated are of lengths that are greater than 255 characters, e.g

C:> copy x y ( where len (x+y) > 255)

As this is throwing an error, is there a work around to manage this kind of situation to increase that command length?

P.S. Some paths+filenames are of length that are larger that 259 characters, to which I found that say there is less to argue

6条回答
劫难
2楼-- · 2019-04-13 09:58

I don't think so; I'd write that to a file maybe.

查看更多
淡お忘
3楼-- · 2019-04-13 10:03
  1. SUBST (has already been proposed)
  2. use 8.3 notation (e.g. C:\Progra~1\ - also has been proposed)
  3. Use this syntax (if you run Command prompt in Windows): copy \?\c:\verylongpath\verylongname \?\d:\anotherverylongpath\
查看更多
手持菜刀,她持情操
4楼-- · 2019-04-13 10:05

You could use subst to name the two subdirectories your working from with drive letters. Obviously the are not real, but logical drives then, but you could substantially shorten the paths.

LASTDRIVE=Z
SUBST S: c:\this is a very long path name\source
SUBST T: d:\this is a very long path name\Target
#do whatever you need to, like
copy s:\filename T:\filename
SUBST S: /D
SUBST T: /D

The /D parameter frees the association.

查看更多
一夜七次
5楼-- · 2019-04-13 10:08

You may want to consider using DBMS_FILE_TRANSFER.COPY_FILE instead of creating a bat file. You can avoid using bat files (which are platform dependent) altogether.

查看更多
劳资没心,怎么记你
6楼-- · 2019-04-13 10:11

Probably no, sounds like you're hitting the MAX_PATH limitation. See File Names, Paths, and Namespaces on MSDN.

Possible workaround might be to use the short path equivalents, e.g. C:\Progra~1.

According to the the following article Command prompt (Cmd. exe) command-line string limitation,

On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

查看更多
仙女界的扛把子
7楼-- · 2019-04-13 10:18

Try using a .cmd file, not a .bat file unless you are using Win95/98/ME. This could solve the entire problem right there.

If that doesn't do it, you can break a command by preceeding a line break with the cmd-escape char ^ or by wrapping the command in parentheses.

查看更多
登录 后发表回答