-
Notifications
You must be signed in to change notification settings - Fork 445
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
windows bat exit code fix #423
Conversation
Return exit code 1 in windows bat script if java application exits with a return code greater than 0. Update windows bat regression tests to check the returned code.
This includes tests for both This pull request targets 0.8.x. Developed and tested on Windows 7 SP1. |
@@ -12,5 +12,10 @@ object Test extends App { | |||
} | |||
} | |||
println("SUCCESS!") | |||
if(System.getenv("return-code-1") == "true"){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems weird to mix tabs and spaces. i know that's what the rest of the file is doing, but i think it'd be nice to replace all the tabs with spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Maybe we target this in a following pr.
Change tabs to spaces and adjust indentats. Print FAILURE for exit code 1 and SUCCESS for exit code 0 in test.
Fix looks good to me (visually). Will check on windows when I can. |
oh. it is good. if you change
↓
then batch error code is same java exit code. so test is
|
Sorry, The above post was wrong . That is not pass negative error code.
↓
all is diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template b/src/main/resources/com/typesafe/sbt/packindex 1cbf0e5..5dab7d7 100644
--- a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template
+++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template
@@ -130,11 +130,11 @@ rem Call the application and pass all arguments unchanged.
@endlocal
-if ERRORLEVEL 1 goto error
+if %ERRORLEVEL% neq 0 goto error
goto end
:error
-set ERROR_CODE=1
+set ERROR_CODE=%ERRORLEVEL%
:end
diff --git a/src/sbt-test/windows/test-bat-template/build.sbt b/src/sbt-test/windows/test-bat-template/build.sbt
index e03b482..ce18a3f 100644
--- a/src/sbt-test/windows/test-bat-template/build.sbt
+++ b/src/sbt-test/windows/test-bat-template/build.sbt
@@ -98,6 +98,8 @@ TaskKey[Unit]("check-script") <<= (stagingDirectory in Universal, name, streams)
// include space and double-quote is failed...
// can't success include double-quote. arguments pass from Process(Seq("-Da=xx\"yy", "aa\"bb")) is parsed (%1="-Da", %2="
//checkOutput(0, "arg #0 is [xx\"yy]\nproperty(test.hoge) is [aa\"bb]\nvmarg #0 is [-Dtest.hoge=aa\"bb]\nSUCCESS!", "-Dte- checkOutputEnv(Map("return-code-1"->"true"), 1, "arg #0 is [RC1]\nFAILURE!", "RC1")
+ checkOutputEnv(Map("return-code"->"1"), 1, "arg #0 is [RC1]\nFAILURE!", "RC1")
+ checkOutputEnv(Map("return-code"->"2"), 2, "arg #0 is [RC2]\nFAILURE!", "RC2")
+ checkOutputEnv(Map("return-code"->"-1"), -1, "arg #0 is [RC-1]\nFAILURE!", "RC-1")
assert(fails.toString == "", fails.toString)
}
diff --git a/src/sbt-test/windows/test-bat-template/src/main/scala/test/Test.scala b/src/sbt-test/windows/test-bat-template/index 8438d82..74d10d0 100644
--- a/src/sbt-test/windows/test-bat-template/src/main/scala/test/Test.scala
+++ b/src/sbt-test/windows/test-bat-template/src/main/scala/test/Test.scala
@@ -11,9 +11,9 @@ object Test extends App {
println("vmarg #" + i + " is [" + x + "]")
}
}
- if(System.getenv("return-code-1") == "true"){
+ if(System.getenv("return-code") != null){
println("FAILURE!")
- System.exit(1)
+ System.exit(System.getenv("return-code").toInt)
} else {
println("SUCCESS!")
System.exit(0) |
If you like, I can push out another commit to this PR and make it so. |
Perhaps too, we could simply exit with: exit /B %ERRORLEVEL% Then we can do away with the ERROR_CODE variable and goto error handling altogether. |
Thanks @nazoking :) It's merged in. |
Thanks a lot for the great team work :) |
Return exit code 1 in windows bat script if java application exits with
a return code greater than 0. Update windows bat regression tests to
check the returned code.