Skip to content

Commit

Permalink
[FIXED JENKINS-25678] Double-double quoting to handle paths with both…
Browse files Browse the repository at this point in the history
… spaces and special characters like @.
  • Loading branch information
jglick committed Feb 20, 2016
1 parent 7b17a50 commit 38fc470
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -54,14 +54,14 @@ public String getScript() {
}
BatchController c = new BatchController(ws);

c.getBatchFile1(ws).write(String.format("cmd /c \"%s\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
c.getBatchFile1(ws).write(String.format("cmd /c \"\"%s\"\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
c.getBatchFile2(ws),
c.getLogFile(ws),
c.getResultFile(ws)
), "UTF-8");
c.getBatchFile2(ws).write(script, "UTF-8");

Launcher.ProcStarter ps = launcher.launch().cmds("cmd", "/c", c.getBatchFile1(ws).getRemote()).envs(envVars).pwd(ws).quiet(true);
Launcher.ProcStarter ps = launcher.launch().cmds("cmd", "/c", "\"\"" + c.getBatchFile1(ws) + "\"\"").envs(envVars).pwd(ws).quiet(true);
listener.getLogger().println("[" + ws.getRemote().replaceFirst("^.+\\\\", "") + "] Running batch script"); // details printed by cmd
/* Too noisy, and consumes a thread:
ps.stdout(listener);
Expand Down
Expand Up @@ -49,8 +49,17 @@ public class WindowsBatchScriptTest {

@Issue("JENKINS-25678")
@Test public void spaceInPath() throws Exception {
doSpaceInPath("space in path");
}

@Issue("JENKINS-25678")
@Test public void spaceInPath2() throws Exception {
doSpaceInPath("space in path@2");
}

private void doSpaceInPath(String name) throws Exception {
StreamTaskListener listener = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath().child("space in path");
FilePath ws = j.jenkins.getRootPath().child(name);
Launcher launcher = j.jenkins.createLauncher(listener);
Controller c = new WindowsBatchScript("echo hello world").launch(new EnvVars(), ws, launcher, listener);
while (c.exitStatus(ws, launcher) == null) {
Expand Down

0 comments on commit 38fc470

Please sign in to comment.