Skip to content
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

Quoting args doesn't work as expected on Windows #41

Closed
Tyriar opened this issue Feb 24, 2017 · 9 comments
Closed

Quoting args doesn't work as expected on Windows #41

Tyriar opened this issue Feb 24, 2017 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug windows
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Feb 24, 2017

Downstream issue: microsoft/vscode#19078

argvToCommandLine makes the following transformation:

cmdline: cmd.exe,/c,dir "a b"
cmdlineFlat: cmd.exe /c "dir \"a b\""
@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug windows labels Feb 24, 2017
@Tyriar Tyriar added this to the 0.6.3 milestone Feb 24, 2017
@Tyriar Tyriar self-assigned this Feb 24, 2017
@Tyriar Tyriar closed this as completed in 28be849 Feb 24, 2017
@Tyriar
Copy link
Member Author

Tyriar commented Feb 24, 2017

@the-ress any feedback on 28be849 would be appreciated 😃

@the-ress
Copy link
Contributor

The problem is that every application can parse the command line differently. The current implementation works well with applications that use CommandLineToArgvW or compatible implementation (node.js and C# applications among others). cmd.exe or batch files handle arguments differently.

So 28be849 breaks escaping for the first group of applications. I would solve the problem in microsoft/vscode#19078 by using ["dir", "test folder"] because that works too, but I can't think think of any universal solution.

@Tyriar
Copy link
Member Author

Tyriar commented Feb 24, 2017

The issue with ["dir", "test folder"] is it's 2 args though so it might behave differently. If the command required escaping within an arg could you not just specify args as ["dir \\"test folder\\""]?

Do you have an example command/args where the change would fail?

@TSlivede
Copy link

TSlivede commented Feb 28, 2017

@Tyriar
I think 28be849 should definitely be reverted:

When calling an executable with an array of arguments, almost every CLI-App splits this Commandline according to these rules (the only exception I currently know of, is old legacy cmd.exe). As node-pty presents an Unix-like interface to conlole applications, it should also provide a unix-like argv[] calling mechanism instead of windows-like escape-Commandline-yourself way. Therefore the Commandline should be build in a way, that matches those rules.

Many modern Commandshells on windows do this:

To solve the problem with cmd, one could allow passing a string as args instead of an array. Or one could explicitly test if cmd.exe is called and then do different processing.

28be849 is very inconsistent (backslashes are escaped, quotes not?). If it is really desired, to let the user quote arguments himself, argvToCommandLine should be completely removed, so the user must enquote and escape the arguments by himself, like in the "Note" box on MSDN: _exec, but this seems somewhat messy...

Examples where 28be849 fails: Starting any other Commandlineapplication than cmd.exe with complicated arguments.

@Tyriar
Copy link
Member Author

Tyriar commented Mar 1, 2017

Thanks for the detailed explanation @TSlivede, makes sense. I was holding off on release until I got someone who knows more about the area to confirm 😄 I'll probably allow args as a string as you suggest:

export function fork(file?: string, args?: string | string[], opt?: IPtyForkOptions): ITerminal

@Tyriar Tyriar reopened this Mar 1, 2017
Tyriar added a commit that referenced this issue Mar 1, 2017
@TSlivede
Copy link

TSlivede commented Mar 1, 2017

@Tyriar Very nice!! 👍 👍 👍
Althought I'd call it ArgsOrCmdline or similar instead of ArgsOrArgv.
Both args and argv are names for Argument-arrays. 😃
CommandLine or CmdLine is the Microsoft terminology for the single argument-string.

@Tyriar
Copy link
Member Author

Tyriar commented Mar 1, 2017

Sounds good 👍

@TSlivede
Copy link

TSlivede commented Mar 1, 2017

Just another note: To solve the problem in microsoft/vscode#19078, one could simply replace cmd.exe,/c,dir "a b" with powershell.exe,/c,dir "a b" and it should work.
Btw: This (with powershell) is one case that breaks with 28be849 😄

One more Note:
In unixTerminal.ts maybe instead of
throw new Error('args as a string is not supported on unix.');
better
throw new Error('args as type string is not supported on unix, please use a string array.');
to tell people what they did wrong?

Tyriar added a commit that referenced this issue Mar 12, 2017
@Tyriar
Copy link
Member Author

Tyriar commented Mar 12, 2017

Fixed in #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug windows
Projects
None yet
Development

No branches or pull requests

3 participants