Skip to content

Problem debugging script with arguments if path to script contains spaces #1526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tms320 opened this issue Sep 12, 2018 · 8 comments
Closed
Assignees
Labels

Comments

@tms320
Copy link

tms320 commented Sep 12, 2018

  • Operating system name and version: Windows 10 x64
  • VS Code version: 1.27.1
  • PowerShell extension version: 1.8.4
code -v
1.27.1
5944e81f3c46a3938a82c701f96d7a59b074cfdc
ia32
$pseditor.EditorServicesVersion
Major  Minor  Build  Revision
1      8      4      0
$PSVersionTable
Name                           Value
PSVersion                      5.1.17134.228
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.228
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

My powershell script "test.ps1" is located in "C:\Program Files (x86)\SomeFolder" folder.
If I start debug this script (F5 key) without command line arguments then everything works fine.
But if I start debug with command line argument (for example "param1") then I get error in powershell console (the message is in russian, sorry:)):

PS C:\Program Files (x86)\SomeFolder> . c:\Program` Files` (x86)\SomeFolder\test.ps1 param1
x86 : Имя "x86" не распознано как имя командлета, функции, файла сценария или выполняемой программы. Проверьте правильность написания имени, а также наличие и правильность пути, после чего повторите попыт
ку.
строка:1 знак:23
+ . c:\Program` Files` (x86)\SomeFolder\test ...
+                       ~~~
    + CategoryInfo          : ObjectNotFound: (x86:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The translation of message to english:
x86: The name "x86" is not recognized as the name of the cmdlet, function, script file, or executable. Check the spelling of the name, as well as the presence and correctness of the path, and then try again
ku.
string: 1 character: 23

PS: I manually set command line argument via 'launch.json' file, for configuration 'PowerShell Launch Current File' as follows:

"args": ["param1"],

I also tried configuration 'PowerShell Launch Current File w/Args Prompt' - the problem remains.
If I move my script in folder without spaces in it's path (for example, "C:\Tmp\SomeFolder") then the problem disappears.

@TylerLeonhardt
Copy link
Member

Thanks for the very detailed issue! It's very helpful. My guess is that we're probably spliting the args string by " " and that's what's causing this. We'll investigate.

@TylerLeonhardt
Copy link
Member

I reread this... question @tms320. Are you debugging with the "PowerShell Interactive Session" debug config?

@TylerLeonhardt
Copy link
Member

I also tried configuration 'PowerShell Launch Current File w/Args Prompt' - the problem remains.

this might be us not properly escaping paths

@tms320
Copy link
Author

tms320 commented Sep 12, 2018

I reread this... question @tms320. Are you debugging with the "PowerShell Interactive Session" debug config?

I tried two debug configurations (defined in launch.json):
First: PowerShell Launch Current File

{
	"type": "PowerShell",
	"request": "launch",
	"name": "PowerShell Launch Current File",
	"script": "${file}",
	"args": ["param1"],
	"cwd": "${file}"
}

Second: PowerShell Launch Current File w/Args Prompt

{
	"type": "PowerShell",
	"request": "launch",
	"name": "PowerShell Launch Current File w/Args Prompt",
	"script": "${file}",
	"args": [
		"${command:SpecifyScriptArgs}"
	],
	"cwd": "${file}"
}

@TylerLeonhardt
Copy link
Member

The first one works and the second one doesn't. Is that correct?

@tms320
Copy link
Author

tms320 commented Sep 12, 2018

The first one works and the second one doesn't. Is that correct?

No. Both configurations work incorrectly.

@TylerLeonhardt
Copy link
Member

Thanks for the info. I think I have an idea of a fix but I need to do some proper testing.

@rjmholt
Copy link
Contributor

rjmholt commented Oct 11, 2018

@tms320 I believe I have a fix for this. Until then, you might be able to work around the issue by putting your arguments in single quotes inside the double quotes (which is silly, but shouldn't be needed later)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants