Issue of input line is too long while executing bat file

2.5k views Asked by At

I have created one automated test which is running a bat file. This abc.bat is generated using application assembler plug-in. Inside bat file, class path has been set and Java commands has been executing). On Linux, it's working fine, but on Windows environment, I am getting the error of:

The input line is too long

The path from which batch file is executing is C:\build\work\work1\abc\abc.bat. I have to keep this path, can't reduce it to like C:\build\abc.bat.

I am using process builder to run this abc.bat file.

public Test(Path wp, Path exe) throws IOException {
builder = new ProcessBuilder()
        .directory(wp.toFile())
        .command(wp.resolve(exe).toAbsolutePath().toString())
        .redirectOutput(Redirect.INHERIT)
        .redirectError(Redirect.INHERIT);

        builder.start();
}

Path wp contains the path of C:\build\work\work1. (I am fetching this path from system environment variables). Path exe contains the path of abc\abc.bat

I have done some research and found out that long path issue can be fixed by changing group policy as shown below:

Hit the Windows key, type gpedit.msc and press Enter.
Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem
and enable win32 long paths.

This doesn't work for me. I am using Windows 10 enterprise, OS build is 14393.1593.

Another way is using Subst command. Manually I can map the drive using command prompt like:

C:\build> Subst X: “C:\build\work\work1” 
X:\>abc\abc.bat

It works fine and there is no issue of "The input line is too long". Is this a good way to overcome this issue? and how to automate this using process builder?

2

There are 2 answers

0
Mr. Man On

According to Microsoft's docs "Maximum Path Length Limitation" that path is not long enough to hit the windows limit.

"The input line is too long" must include other characters, possibly parameters being passed to the bat file, or parameters being used to call that bat file.

To get a better picture of what is actually being executed, turn on command line process auditing in windows. Command line process auditing

If you are somehow hitting that limit, and parameter passing is happening, I suggest finding a different way to get to that information, possibly by saving to and reading from a file.

0
Thomas N On

Also the contents of the PATH environment variable matters. Maybe you are adding to this? If it is too long you can get same error. Depending on windows version it can be as low as 2048