/arduino-core/src/processing/app/tools/DoubleQuotedArgumentsOnWindowsCommandLine.java

https://github.com/sgk/Arduino · Java · 35 lines · 22 code · 8 blank · 5 comment · 2 complexity · 9478a6b3db139ed85508013a07d53d1c MD5 · raw file

  1. package processing.app.tools;
  2. import org.apache.commons.exec.CommandLine;
  3. import processing.app.helpers.OSUtils;
  4. import java.io.File;
  5. public class DoubleQuotedArgumentsOnWindowsCommandLine extends CommandLine {
  6. public DoubleQuotedArgumentsOnWindowsCommandLine(String executable) {
  7. super(executable);
  8. }
  9. public DoubleQuotedArgumentsOnWindowsCommandLine(File executable) {
  10. super(executable);
  11. }
  12. public DoubleQuotedArgumentsOnWindowsCommandLine(CommandLine other) {
  13. super(other);
  14. }
  15. @Override
  16. public CommandLine addArgument(String argument, boolean handleQuoting) {
  17. // Brutal hack to workaround windows command line parsing.
  18. // http://stackoverflow.com/questions/5969724/java-runtime-exec-fails-to-escape-characters-properly
  19. // http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
  20. // http://bugs.sun.com/view_bug.do?bug_id=6468220
  21. // http://bugs.sun.com/view_bug.do?bug_id=6518827
  22. if (argument.contains("\"") && OSUtils.isWindows()) {
  23. argument = argument.replace("\"", "\\\"");
  24. }
  25. return super.addArgument(argument, handleQuoting);
  26. }
  27. }