Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Getting Windows Enviroment Variables removes backslashes #2115

nmanos ·
Hi,
Trying to run a step with shell command (assuming User directory is "MY_USER"):
xcopy.exe myscript.bat "${node.getAttribute("USERPROFILE")}/Start Menu/Programs/Startup/"


was translated into path with a missing backslash:

INFO - D:\QB_Agent\workspace\3748\myscript.bat -> C:[b]Documents and SettingsMY_USER[/b]/Start Menu/Programs/Startup/myscript.bat


I fixed it by running instead:
cmd /c xcopy.exe myscript.bat "%USERPROFILE%/Start Menu/Programs/Startup/"

Thanks,
Noam.
  • replies 6
  • views 2954
  • stars 0
robinshen ADMIN ·
Backslash will be translated as escaping character, so you will have to use forward slash in your command, or use double backslash instead.
nmanos ·
Using double-backslash or slashes doesn't solve the problem of ${node.getAttribute("USERPROFILE")} being translated into Win path without middle backslash:

xcopy.exe myscript.bat "${node.getAttribute("USERPROFILE")}\Start Menu\Programs\Startup\"

INFO - D:\QB_Agent\workspace\3748\myscript.bat -> C:[b]Documents and SettingsMY_USER[/b]\Start Menu\Programs\Startup\myscript.bat


Only when I preceded the xcopy with cmd -c - it worked.
robinshen ADMIN ·
Or you may write the command as below:
xcopy.exe myscript.bat "${node.getAttribute("USERPROFILE").replace("\", "\\")}\Start Menu\Programs\Startup\"
nmanos ·
Thanks Robin, this was indeed the solution <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) --> - to run command line with windows path including spaces, and without the cmd /c.
Here's another example where I implemented it:

setx.exe PATH "${node.getAttribute("Path").replace("\", "\\")};${node.getAttribute("SystemDrive")}\${groovy:
String pythonDir;
new File(node.getAttribute("SystemDrive")).eachFile() { file->
if (file.getName().startsWith("Python") && file.isDirectory()) {
pythonDir = file.getName();
logger.debug("pythonDir= " + pythonDir);
\}
\}
return pythonDir;
}" -m


The above script adds Python Path to Windows Envvironment Variable %Path% (which includes many spaces).

Thanks,
Noam.
Sharon-Cutie ·
I am planning to go for Windows 8. Would I have any problems?
robinshen ADMIN ·
Backslashes works the same way in Win8. So you probably need to adopt the same approaches here.