'The input line is too long when starting kafka
I'm trying to run Kafka message queue on Windows.
I'm usin this tutorial - https://dzone.com/articles/running-apache-kafka-on-windows-os
When i try to run it with comand - .\bin\windows\kafka-server-start.bat .\config\server.properties
and i get an error: The input line is too long. The syntax of the command is incorrect.
kafka location - C:\kafka_2.11-1.0.0
Solution 1:[1]
This is because of the long length of the path because of the folder name 'kafka_2.11-1.0.0'. Just rename the folder to something small, like just 'kafka'.
Solution 2:[2]
The Problem
The kafka-run-class.bat
file performs a bunch of CLASSPATH :concat calls that make the CLASSPATH very long.
Depending on your environment, too long: Windows cmd.exe environment has a limit of 8191 characters.
Solutions
Edit kafka-run-class.bat
so that ...
- make it so that CLASSPATH is not used or set elsewhere
- make paths shorter so that concat produces a string smaller than than 8191 characters
- make concat use the whole folder instead of every single jar (via
libs/*
)
Example
Here is an example of an edit to kafka-run-class.bat
(source) that uses the 2nd approach:
replace ...
rem Classpath addition for release
for %%i in ("%BASE_DIR%\libs\*") do (
call :concat "%%i"
)
... by this ...
rem Classpath addition for release
call :concat "%BASE_DIR%\libs\*;"
Solution 3:[3]
Just moving the Kafka path to a much smaller root path solved the issue. For e.g. "C:\Kafka"
Solution 4:[4]
Above both options didn't work for me.
I have just moved an unzipped directory to C:/ drive and started power shell in Administrator mode and tried the desired commands, the zookeeper and broker started smoothly.
Solution 5:[5]
I have copied everything to C:/tools/kafka and it works fine. The problem was indeed the too long path to kafka.
Solution 6:[6]
For me, it worked only after keeping the Kafka folder right under C directory, so the path looked like C:\Kafka. I am sure this will work.
Solution 7:[7]
Windows command-line has issues with long command execution. Use Powershell instead.
Solution 8:[8]
put all the files in other drive like D: or E: and run the command
Solution 9:[9]
Place kafka close to the root of your drive so that the path to it is very short.
When you run those Kafka batch files included in the windows directory, they muck with your environment variables (the classpath one) and can create a very long input line to actually run the command/jar.
Also as some others pointed out, ensure you downloaded the binary (yes even though on the Kafka site it is called the Scala binary and there's no mention of Windows anywhere, which can confuse people), not the source code. Also confusing to the lay-user, the source distribution looks similar to the binary distribution when uncompressed, it has all the batch files for example but they won't run.
Solution 10:[10]
The input line is too long when starting kafka
I tried below command but gives me same error
C:\kafka>.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
This happens because path gets append in classpath when we are continuously executing same command on same cmd.
Close your command prompt and open once again and then start zookeeper server.
Solution 11:[11]
For Windows just keep Kafka Folder path short For eg - D/dev/kafka/bin/windows
Solution 12:[12]
Closing Zookeeper and Kafka cmd window and reopening it again worked for me. I tried all options above except powershell.
Solution 13:[13]
Rename the kafka folder to some shorter name like kafka2. Open a new command prompt (DO not use existing/opened command prompt)
Solution 14:[14]
I tried extracting the downloaded Kafka zip file contacts
C:\Kafka and ran the Kafka-server-start.bat
from the command prompt (don't run the command prompt as administrator) and that worked.
Running the command prompt as administrator was causing the problem for me.
Solution 15:[15]
Remove kafka_2.13-2.5.0
if there's any and keep the folder name as simple as possible like Kafka
, also make sure there are no spaces in the path.
A working example: Folder is located in C:\kafka
.
A not working example: Folder is located in C:\kafka 2\
.
Solution 16:[16]
I had this problem too. Debugging the bat-files, you can see, that changing into the directory before calling the command that returns with this error and calling it with relative path does not afect the result! The problem is the CLASSPATH variable. The easiest way to get this shorter for me was to use the command:
subst K: <absolute-long-path-to-kafka-dir-with-version>
This way I could change into this virtual drive cd /d K:
and execute the scripts without problem:
K:\bin\windows\kafka-server-start.bat K:\config\server.properties
I wrote a wrapper-script that removes the CLASSPATH variable before executing again, because the values are appended every execution (same cmd.exe).
set CLASSPATH=
cd /d K:
K:\bin\windows\kafka-server-start.bat K:\config\server.properties
Solution 17:[17]
I'm using scoop. Changing ...bin\windows\kafka-run-class.bat as below (kudos Midiman) fixed it for me:
@REM rem Classpath addition for kafka-core dependencies
@REM for %%i in ("%BASE_DIR%\core\build\dependant-libs-%SCALA_VERSION%\*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\core\build\dependant-libs-%SCALA_VERSION%\*"
@REM rem Classpath addition for kafka-examples
@REM for %%i in ("%BASE_DIR%\examples\build\libs\kafka-examples*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\examples\build\libs\*"
@REM rem Classpath addition for kafka-clients
@REM for %%i in ("%BASE_DIR%\clients\build\libs\kafka-clients*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\clients\build\libs\*"
@REM rem Classpath addition for kafka-streams
@REM for %%i in ("%BASE_DIR%\streams\build\libs\kafka-streams*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\streams\build\libs\*"
@REM rem Classpath addition for kafka-streams-examples
@REM for %%i in ("%BASE_DIR%\streams\examples\build\libs\kafka-streams-examples*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\streams\examples\build\libs\*"
@REM for %%i in ("%BASE_DIR%\streams\build\dependant-libs-%SCALA_VERSION%\rocksdb*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\streams\build\dependant-libs-%SCALA_VERSION%\*"
@REM rem Classpath addition for kafka tools
@REM for %%i in ("%BASE_DIR%\tools\build\libs\kafka-tools*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\tools\build\libs\*"
@REM for %%i in ("%BASE_DIR%\tools\build\dependant-libs-%SCALA_VERSION%\*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\tools\build\dependant-libs-%SCALA_VERSION%\*"
for %%p in (api runtime file json tools) do (
@REM for %%i in ("%BASE_DIR%\connect\%%p\build\libs\connect-%%p*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\connect\%%p\build\libs\*"
if exist "%BASE_DIR%\connect\%%p\build\dependant-libs\*" (
call :concat "%BASE_DIR%\connect\%%p\build\dependant-libs\*"
)
)
@REM rem Classpath addition for release
@REM for %%i in ("%BASE_DIR%\libs\*") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\libs\*"
@REM rem Classpath addition for core
@REM for %%i in ("%BASE_DIR%\core\build\libs\kafka_%SCALA_BINARY_VERSION%*.jar") do (
@REM call :concat "%%i"
@REM )
call :concat "%BASE_DIR%\core\build\libs\*"
Solution 18:[18]
Rename kafka_2.11-1.0.0 to kafka and keep it in C drive. This worked for me.
Solution 19:[19]
Please check the directory path of your files, it should not contain any "-" in your directory structure where you have kept Kafka. Changing the name of the directory from kafka_2.13-2.7.0 --> Kafka worked for me.
Solution 20:[20]
Another good way to solve this is to create a virtual drive from the kafka folder:
subst <drive:> path\to\folder
example:
subst K: C:\Users\me\software\kafkax.x-x.x
You can then go to the K: drive and run zookeeper and kafka without problem.
cd K:
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
.\bin\windows\kafka-server-start.bat .\config\server.properties
Solution 21:[21]
Run common .\bin\windows\kafka-server-start.bat .\config\server.propertie from Powershell window, it works without any issue on Window.
For a similar error, for zookeeper I run the zookeeper zkserver.cmd which i downloaded from https://zookeeper.apache.org/doc/r3.6.2/zookeeperStarted.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow