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

fix windows batch argument probrem. #393

Merged
merged 6 commits into from
Nov 26, 2014

Conversation

nazoking
Copy link
Contributor

the shift command of cmd.exe is not shift %*.
and use delayed-expansion. immediate expansion cause many troubles of special-characters in arguments.

the `shift` command of cmd.exe is not shift `%*`.
and use delayed-expansion. immediate expansion cause many troubles of special-characters in arguments.
@lightbend-cla-validator

Hi @nazoking,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement:

http://typesafe.com/contribute/cla

@nazoking
Copy link
Contributor Author

#72

@@ -15,7 +16,7 @@ set "APP_LIB_DIR=%@@APP_ENV_NAME@@_HOME%\lib\"

rem Detect if we were double clicked, although theoretically A user could
rem manually run cmd /c
for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1
for %%x in (!cmdcmdline!) do if %%~x==/c set DOUBLECLICKED=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between % and !?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! is delayed-expansion literal. I understood %ENV% expanded before parse time. !ENV! after parse time, before run time.

>type test.bat
SET A=%1
if NOT "!A!" == "" echo "OK"

>test a"a

SET A=a"a
The syntax of the command is incorrect.
if NOT "a"a" == "" echo "OK"
SET A=%1
if NOT "!A!" == "" echo "OK"

>test a"a
SET A=a"a
if NOT "!A!" == "" echo "OK"
"OK"

@muuki88
Copy link
Contributor

muuki88 commented Oct 27, 2014

Thanks a lot for this pull request. Can instead of changing the already existing test, create a new one?

@nazoking
Copy link
Contributor Author

OK. I create new test.

@muuki88
Copy link
Contributor

muuki88 commented Oct 28, 2014

I tried this on my windows-7 machine. The test fails inside cmd and the powershell. Both with

[info] [error] (*:checkScript) java.lang.AssertionError:
[info] [error] ---------------------------------
[info] [error] Failed to correctly run the main script!.
[info] [error] "cmd" "/c" "C:\Users\nseiler\AppData\Local
ge=\[]!< >%"" "\[]!< >%" "-Dtest.huga="\[]!<>%""
[info] [error]
[info] [error] --expected----------------------------
[info] [error] arg #0 is [\[]!< >%]
[info] [error] property(test.hoge) is [\[]!< >%]
[info] [error] property(test.huga) is [\[]!<>%]
[info] [error] SUCCESS!
[info] [error]
[info] [error] --found-------------------------------
[info] [error] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] [error] error code: 1
[info] [error] Total time: 4 s, completed 28.10.2014 23:3
[error] x windows / test-bat-template
[error]    {line 4}  Command failed: check-script failed

kann syntaktisch an dieser Stelle nicht verarbeitet werden

Means more ore less can syntactically not be processed here

@nazoking
Copy link
Contributor Author

wmm I tried this on my windows-7 machine. The test success inside cmd.

>cmd /V
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

I added more test fail report on fail. please try and report agin.

@muuki88
Copy link
Contributor

muuki88 commented Oct 29, 2014

Hm. Same error. I found another one for the normal java-app, remove the import NativePackagerKeys._.

Error in powershell

[info] java.lang.AssertionError: assertion failed:
[info] ---------------------------------
[info] Failed to correctly run the main script!.
[info] "cmd" "/c" "C:\Users\nseiler\AppData\Local\Temp\sbt_b65d6270
-test.bat" ""-Dtest.hoge=\[]!< >%"" "\[]!< >%" "-Dtest.huga="\[]!<>
[info]
[info] --expected----------------------------
[info] arg #0 is [\[]!< >%]
[info] property(test.hoge) is [\[]!< >%]
[info] property(test.huga) is [\[]!<>%]
[info] SUCCESS!
[info]
[info] --found-------------------------------
[info] error < ">"  kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] error code: 1
[info]
[info] --detail-------------------------------
[info] error < ">"  kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info]
[info]  at scala.Predef$.assert(Predef.scala:179)
[info]  at $161c46dea5a88d9febeb$$anonfun$$sbtdef$1.apply(C:\Users\
late\build.sbt:93)
[info]  at $161c46dea5a88d9febeb$$anonfun$$sbtdef$1.apply(C:\Users\
late\build.sbt:37)
[info]  at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:
[info]  at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:
[info]  at scala.Function1$$anonfun$compose$1.apply(Function1.scala
[info]  at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions
[info]  at sbt.std.Transform$$anon$4.work(System.scala:63)
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Exe
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Exe
[info]  at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
[info]  at sbt.Execute.work(Execute.scala:235)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
[info]  at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(Conc
[info]  at sbt.CompletionService$$anon$2.call(CompletionService.sca
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.Executors$RunnableAdapter.call(Exec
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.ThreadPoolExecutor.runWorker(Thread
[info]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Threa
[info]  at java.lang.Thread.run(Thread.java:724)
[info] [error] (*:checkScript) java.lang.AssertionError: assertion
[info] [error] ---------------------------------
[info] [error] Failed to correctly run the main script!.
[info] [error] "cmd" "/c" "C:\Users\nseiler\AppData\Local\Temp\sbt_
\windows-test.bat" ""-Dtest.hoge=\[]!< >%"" "\[]!< >%" "-Dtest.huga
[info] [error]
[info] [error] --expected----------------------------
[info] [error] arg #0 is [\[]!< >%]
[info] [error] property(test.hoge) is [\[]!< >%]
[info] [error] property(test.huga) is [\[]!<>%]
[info] [error] SUCCESS!
[info] [error]
[info] [error] --found-------------------------------
[info] [error] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] [error] error code: 1
[info] [error]
[info] [error] --detail-------------------------------
[info] [error] error < ">" kann syntaktisch an dieser Stelle nicht
[info] [error] Total time: 4 s, completed 29.10.2014 22:04:24

Aswell as cmd

[info] java.lang.AssertionError: assertion failed:
[info] ---------------------------------
[info] Failed to correctly run the main script!.
[info] "cmd" "/c" "C:\Users\nseiler\AppData\Local\Temp\sbt_9a0da522\test-bat-template\target\universal\stage\bin\windows-test.bat" ""-Dtest.hoge=\[]!<
 >%"" "\[]!< >%" "-Dtest.huga="\[]!<>%""
[info]
[info] --expected----------------------------
[info] arg #0 is [\[]!< >%]
[info] property(test.hoge) is [\[]!< >%]
[info] property(test.huga) is [\[]!<>%]
[info] SUCCESS!
[info]
[info] --found-------------------------------
[info] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] error code: 1
[info]
[info] --detail-------------------------------
[info] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info]
[info]  at scala.Predef$.assert(Predef.scala:179)
[info]  at $1b0f416a1de260ed5461$$anonfun$$sbtdef$1.apply(C:\Users\nseiler\AppData\Local\Temp\sbt_9a0da522\test-bat-template\build.sbt:93)
[info]  at $1b0f416a1de260ed5461$$anonfun$$sbtdef$1.apply(C:\Users\nseiler\AppData\Local\Temp\sbt_9a0da522\test-bat-template\build.sbt:37)
[info]  at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:35)
[info]  at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:34)
[info]  at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[info]  at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
[info]  at sbt.std.Transform$$anon$4.work(System.scala:63)
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
[info]  at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
[info]  at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
[info]  at sbt.Execute.work(Execute.scala:235)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
[info]  at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
[info]  at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
[info]  at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
[info]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[info]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[info]  at java.lang.Thread.run(Thread.java:724)
[info] [error] (*:checkScript) java.lang.AssertionError: assertion failed:
[info] [error] ---------------------------------
[info] [error] Failed to correctly run the main script!.
[info] [error] "cmd" "/c" "C:\Users\nseiler\AppData\Local\Temp\sbt_9a0da522\test-bat-template\target\universal\stage\bin\windows-test.bat" ""-Dtest.ho
ge=\[]!< >%"" "\[]!< >%" "-Dtest.huga="\[]!<>%""
[info] [error]
[info] [error] --expected----------------------------
[info] [error] arg #0 is [\[]!< >%]
[info] [error] property(test.hoge) is [\[]!< >%]
[info] [error] property(test.huga) is [\[]!<>%]
[info] [error] SUCCESS!
[info] [error]
[info] [error] --found-------------------------------
[info] [error] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] [error] error code: 1
[info] [error]
[info] [error] --detail-------------------------------
[info] [error] error < ">" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
[info] [error] Total time: 3 s, completed 29.10.2014 22:10:05
[error] x windows / test-bat-template
[error]    {line 4}  Command failed: check-script failed
[trace] Stack trace suppressed: run last *:scripted for the full output.
[error] (*:scripted) Failed tests:
[error]         windows / test-bat-template
[error] Total time: 37 s, completed 29.10.2014 22:10:06
>

@nazoking
Copy link
Contributor Author

mm.. the result teach batch is not called...

please try scala console (REPL)

 $ console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.

scala> sys.process.Process(Seq("cmd","/c","echo -Dtest.huga=\"\\[]!<>\"")).!!
res0: String =
"-Dtest.huga="\[]!<>"

can run this script ( sys.process.Process(Seq("cmd","/c","echo -Dtest.huga=\"\\[]!<>\"")).!! ) in your system?

@muuki88
Copy link
Contributor

muuki88 commented Nov 1, 2014

[info]
Welcome to Scala version 2.10.2 (Java HotSpot(TM) Client VM, Java 1.7.0_40).
Type in expressions to have them evaluated.
Type :help for more information.

scala> sys.process.Process(Seq("cmd","/c","echo -Dtest.huga=\"\\[]!<>\"")).!!
res0: String =
"-Dtest.huga="\[]!<>"
"

seem to work

@nazoking
Copy link
Contributor Author

m.......... I split test each arguments.please try it....

@muuki88
Copy link
Contributor

muuki88 commented Nov 10, 2014

Okay. This must be something with my locale/encoding setup. @jsuereth @kardapoltsev @fiadliel you have any options to validate this PR as well?

@@ -72,86 +73,60 @@ if "%JAVAOK%"=="false" (

rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config.
set _JAVA_OPTS=%JAVA_OPTS%
if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=%CFG_OPTS%
if "!_JAVA_OPTS!"=="" set _JAVA_OPTS=!CFG_OPTS!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOH, good catch.

@jsuereth
Copy link
Member

@muuki88 My windows laptop is out of commission temporarily (AC power cord got recalled due to causing fires). Can this wait a few days for the new cord to show up so I can test on an en_US locale?

@muuki88
Copy link
Contributor

muuki88 commented Nov 11, 2014

Yeah sure. @nazoking was really patient with me until now :-)

@jsuereth
Copy link
Member

Ok, this looks great, ran the tests. One comment ->

src/sbt-test/windows/test-app-archetype/build.sbt needs to remove the import SbtNativePackagerKeys._ and then everything passes with flying colors.

SO, this LGTM to merge and we can issue a fix to the scripted test in a different PR.

Sorry this took so long.

@muuki88
Copy link
Contributor

muuki88 commented Nov 20, 2014

Awesome. @nazoking can you remove the import statement an then we merge this :)

@nazoking
Copy link
Contributor Author

Thanks you. I remove it.

muuki88 added a commit that referenced this pull request Nov 26, 2014
…ments

fix windows batch argument probrem.
@muuki88 muuki88 merged commit 54d16c6 into sbt:master Nov 26, 2014
@muuki88
Copy link
Contributor

muuki88 commented Nov 26, 2014

Thanks a lot for your work :)

@muuki88
Copy link
Contributor

muuki88 commented Nov 26, 2014

merged in 0.8.x and 0.7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants