data-weave-cli icon indicating copy to clipboard operation
data-weave-cli copied to clipboard

dw should get the AppData/LocalAppData folder locations on Windows without crashing due to a PowerShell $Profile script

Open BrianL-STCU opened this issue 3 years ago • 0 comments

Describe the bug To get the ApplicationData and LocalApplicationData user folders on Windows, a complex PowerShell command line is used, but can be broken if the user's PowerShell profile script has unexpected output.

To Reproduce Steps to reproduce the behavior:

  1. Add the following to your PowerShell $Profile script:
Write-Host "?`n?"
  1. Run dw "output application/json --- true"
  2. Get a stack trace of java.nio.file.InvalidPathException: Illegal char <?> at index 0

Expected behavior The AppData and LocalAppData folders are available as simple environment variables (APPDATA and LOCALAPPDATA, respectively), or you can use the simple PowerShell expressions [Environment]::GetFolderPath('ApplicationData') and [Environment]::GetFolderPath('LocalApplicationData') without compiling C# code via Add-Type to get at the low-level Windows API. But if you use PowerShell, be sure to include the -NoProfile and -NonInteractive parameters for the powershell.exe, otherwise the user profile script is implicitly executed before your -Command parameter, which can have unexpected results, and can even block execution.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10 version 20H2
  • Windows PowerShell 5.1.19041.546
  • DataWeave Command Line : V1.0.9
  • DataWeave Runtime: V2.3.2-SNAPSHOT

BrianL-STCU avatar Dec 10 '20 01:12 BrianL-STCU