Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7872#discussion_r36245348
--- Diff:
yarn/src/test/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtilSuite.scala
---
@@ -70,6 +79,31 @@ class YarnSparkHadoopUtilSuite extends SparkFunSuite
with Matchers with Logging
}
}
+ def cmdTest(name: String)(fn: => Unit): Unit =
+ if (isWindows) test(name)(fn) else ignore(name)(fn)
+
+ cmdTest("cmd shell script escaping") {
+ val scriptFile = File.createTempFile("script.", ".cmd",
Utils.createTempDir())
+ val args = Array("arg1", "${arg.2}", "\"arg3\"", "'arg4'", "$arg5",
"\\arg6")
+ System.out.println(s"Test Arguments: ${args.mkString(" ")}")
+ try {
+ val argLine = args.map(a =>
YarnSparkHadoopUtil.escapeForShell(a)).mkString(" ")
+ Files.write(("cmd /C \"@echo " + argLine + "\"").getBytes(),
scriptFile)
+ scriptFile.setExecutable(true)
+System.out.println(s"Escaped Arguments: $argLine")
+ val proc =
Runtime.getRuntime().exec(Array(scriptFile.getAbsolutePath()))
+ val out = new
String(ByteStreams.toByteArray(proc.getInputStream())).trim()
+ val err = new String(ByteStreams.toByteArray(proc.getErrorStream()))
+ val exitCode = proc.waitFor()
+ exitCode should be (0)
+ System.out.println(s"Output: $out")
--- End diff --
Please don't print to stdout. If you really need to, extend `Logging` and
use one of the log methods. But it really feels like you should just use
`Utils.executeAndGetOutput`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]