kotlin-compiler-2.2.21.zip
Environment Variable: KOTLIN_HOME
- KOTLIN_HOME -> D:\TOOLS\kotlinc
Environment Variable: PATH
- PATH -> D:\TOOLS\kotlinc\bin
D:\My Drive\Test Script\test.kts
println("I am runnable!")
Test
Open CMD.exe
Test OK
kotlin "D:\\My Drive\\Test Script\\test.kts"
kotlin "D:/My Drive/Test Script/test.kts"
kotlin "D:\My Drive\Test Script\test.kts"
Microsoft Windows [Version 10.0.17763.1935]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\IEUser>kotlin "D:\\My Drive\\Test Script\\test.kts"
I am runnable!
C:\Users\IEUser>kotlin "D:/My Drive/Test Script/test.kts"
I am runnable!
C:\Users\IEUser>kotlin "D:\My Drive\Test Script\test.kts"
I am runnable!
Test Fail
Open CMD.exe
Run kotlin under directory path contain space char.
D:
cd "D:\My Drive\Test Script"
kotlin "test.kts"
D:\My Drive\Test Script>kotlin "test.kts"
exception: java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/My%20Drive/Test%20Script/./
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)

kotlin.bat
@echo off
setlocal EnableDelayedExpansion
REM ==========================================
REM Part 1: Display Directory Information
REM ==========================================
echo ---------------------------------------------------
echo [INFO] Script location: "%~dp0"
echo [INFO] Working directory: "%cd%"
echo ---------------------------------------------------
REM ==========================================
REM Part 2: Process Arguments One by One
REM ==========================================
set "NEW_ARGS="
:ProcessArgs
if "%~1"=="" goto :EndArgs
set "CURRENT_ARG=%~1"
set "CURRENT_EXT=%~x1"
set "IS_KOTLIN=0"
if /i "!CURRENT_EXT!"==".kt" set "IS_KOTLIN=1"
if /i "!CURRENT_EXT!"==".kts" set "IS_KOTLIN=1"
if "!IS_KOTLIN!"=="1" (
REM Convert to absolute path
set "PROCESSED_ARG="%~f1""
echo [PROCESSING] Kotlin file found: "%~1" -^> Converted to: !PROCESSED_ARG!
) else (
set "PROCESSED_ARG=%1"
)
if defined NEW_ARGS (
set "NEW_ARGS=!NEW_ARGS! !PROCESSED_ARG!"
) else (
set "NEW_ARGS=!PROCESSED_ARG!"
)
shift /1
goto :ProcessArgs
:EndArgs
REM ==========================================
REM Part 3: The Handover
REM ==========================================
echo.
echo [INFO] Passing arguments to kotlinc.bat:
echo !NEW_ARGS!
echo ---------------------------------------------------
REM Pass variable out of setlocal
for /f "delims=" %%a in ("!NEW_ARGS!") do (
endlocal
set "FINAL_ARGS=%%a"
)
REM ==========================================
REM Part 4: Call the Official Script (SAFE MODE)
REM ==========================================
rem Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
setlocal
set _KOTLIN_RUNNER=1
REM --- CRITICAL FIX ---
REM The Kotlin Runner crashes if the Current Working Directory contains spaces (InvalidPathException).
REM We temporarily switch directory (pushd) to the script's own folder (%~dp0),
REM which is usually a safe path like "D:\TOOLS\kotlinc\bin\", to avoid the crash.
pushd "%~dp0"
REM echo [INFO] Temporarily switched to safe directory: "%cd%"
REM Call kotlinc.bat (it is in the current directory now)
call kotlinc.bat %FINAL_ARGS%
popd
This is a modified kotlin.bat file that allows you to execute kotlin test.kts in directory paths containing whitespace characters.
However, it still does not support deploying kotlin in directories containing whitespace characters in the path.
") around a command path that contains spaces.child_process.spawn, which doesn't seem to work when both arguments and the path have spaces (github.com/nodejs/node/issues/7367). I recommend to push for a solution in those GitHub issues."""$pwd\test.kts"""might workaround it in PowerShell. Otherwise, this might also workaround the issue in PowerShell:$fso = New-Object -ComObject Scripting.FileSystemObject; kotlin $fso.getfile("$pwd\test.kts").ShortPath