Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50662][PYTHON][WINDOWS] Escape ampersands in command arguments on windows #49286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/spark-class2.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ rem executed by the batch interpreter. So read all the output of the launcher in
set LAUNCHER_OUTPUT=%temp%\spark-class-launcher-output-%RANDOM_SUFFIX%.txt

rem unset SHELL to indicate non-bash environment to launcher/Main
setlocal enabledelayedexpansion

set args=%*
set args="!args:&=^^^&!"
set SHELL=
"%RUNNER%" -Xmx128m -cp "%LAUNCH_CLASSPATH%" org.apache.spark.launcher.Main %* > %LAUNCHER_OUTPUT%
"%RUNNER%" -Xmx128m -cp "%LAUNCH_CLASSPATH%" org.apache.spark.launcher.Main !args:~1,-1! > %LAUNCHER_OUTPUT%
endlocal
for /f "tokens=*" %%i in (%LAUNCHER_OUTPUT%) do (
set SPARK_CMD=%%i
)
Expand Down
6 changes: 5 additions & 1 deletion bin/spark-submit.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ rem environment, it just launches a new cmd to do the real work.

rem The outermost quotes are used to prevent Windows command line parse error
rem when there are some quotes in parameters, see SPARK-21877.
cmd /V /E /C ""%~dp0spark-submit2.cmd" %*"
setlocal enabledelayedexpansion
set args=%*
set args="!args:&=^^^&!"
cmd /V /E /C ""%~dp0spark-submit2.cmd" !args:~1,-1!"
endlocal
6 changes: 5 additions & 1 deletion bin/spark-submit2.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ rem environment, it just launches a new cmd to do the real work.
rem disable randomized hash for string in Python 3.3+
set PYTHONHASHSEED=0

setlocal enabledelayedexpansion
set CLASS=org.apache.spark.deploy.SparkSubmit
"%~dp0spark-class2.cmd" %CLASS% %*
set args=%*
set args="!args:&=^^^&!"
"%~dp0spark-class2.cmd" %CLASS% !args:~1,-1!
endlocal
4 changes: 4 additions & 0 deletions python/pyspark/java_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def launch_gateway(conf=None, popen_kwargs=None):
command = [os.path.join(SPARK_HOME, script)]
if conf:
for k, v in conf.getAll():
# On windows escape & with triple carets to avoid it being removed by cmd.exe
if on_windows:
v = v.replace("&", "^^^&")

command += ["--conf", "%s=%s" % (k, v)]
submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "pyspark-shell")
if os.environ.get("SPARK_TESTING"):
Expand Down
Loading