-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Give access to raw command line arguments on Windows #9871
Comments
From reading other posts (thread #3892), I gather that the project doesn't currently want to supply access to OS specific APIs. And I don't know if it's relevant to any other platforms, but really only adds potential parity with POSIX systems for Windows applications. This capability could very simply be added as something like |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Not stale. |
@rivy What is the Node / Go behaviour here? |
I don’t think processes have access to the original command line (except cmd on windows, but cmd doesn’t do shell globbing) |
Re-reading this, seems that @rivy's feature request is implied here:
On unix, the quotes are interpreted by the shell; the application won't have access to it. So in order to protect yourself and the rest of the world, Deno won't provide access to the raw command line ;) PS: the thing to do on windows is to always expand glob patterns, quoted or not. |
@lucacasonato , @piscisaureus , TLDR; this is needed for reasonable cross-platform support and I've prototyped a full-featured alternate solution to show it's utility. ... long post ... Although what you said about *nix/POSIX is generally true, the rest is just false. First, for *nix/POSIX, I know that the command line is not even available, hence my suggestion that Windows, however, has a long tradition of minimal shell support, forcing applications to go their own route to correctly parse and expand the command line. Most applications, when they do a reasonable and reliable job of it, reparse the command line from GetCommandLineA/W. And there a digital ton of modern command line utilities which reparse the command line just to support correct basic globbing (see most rust utilities, [eg, Given that you And, addressing your PS aside... No, you shouldn't always expand glob patterns on the Windows platform. It's a more nuanced problem. For example, just the simple command string Deno seems to have made strong efforts for cross-platform portability and to support Windows/CMD. This step (or some other variation) can help make that effort much more robust and work toward a goal of "a command line execution string means the same thing regardless of platform". I can make big strides towards parity between the *nix/POSIX and Windows platforms when I'm able to access that initial Windows command line. As proof-of-concept, while waiting on replies to this, #9873, and #9874, I've gone ahead and prototyped a process library which works with enhanced script runners and/or an enhanced shim to supply improved quoting and bash-like command line expansion for Windows platforms. I leveraged the well-regarded braces and picomatch NPMjs libraries to supply full feature brace expansion, fully implemented advanced glob expansion (notably with with path-separator independence), sane double and single quoting, and support for ANSI-C quoted strings (eg, $'\n'). The prototype is somewhat raw and almost certainly has some rough corner cases, but it's already very capable. This allows for the exact same command line expressions on Windows or *nix (bash/POSIX-compatible shell) platforms; for example, when installed with the enhanced shim, See deno install -Af https://deno.land/x/dxx@v0.0.2/src/dxi.ts
dxi -Af https://deno.land/x/dxx@v0.0.2/src/dxr.ts
dxr https://deno.land/x/dxx@v0.0.2/eg/args.ts --debug --lines "*" {,.}* $'\e[31mANSI-C string\e[m' 'single quotes' I also have some ideas about adding in command line variable expansion (environment variables and sub-shell expansions) but that will entail a more complicated parsing step and some development time. And I plan to back-port all of the bash-like parsing/expansion to P.S. The enhanced shim fixes the "Terminate batch job (Y/N)?" issue as well. |
Sorry, I'm not buying this at all. What you're trying to do is not useful; I'm sure that with access to the raw command like you can write a program that distinguishes between In the meantime, all windows software treats Single quotes (') are also a losing proposition: |
This seems to be devolving from discussion, but I'll address your points...
Simply, and provably, not true. deno install -Af https://deno.land/x/dxx@v0.0.3/src/dxi.ts
dxi -Af https://deno.land/x/dxx@v0.0.3/eg/args.ts
args '*' *
node -e "const {exec} = require('child_process'); exec('args \'*\' *', (e, out, err) => console.log(out));"
perl -e "system(q{args '*' *})"
powershell -c args --% '*' *
python -c "import subprocess; subprocess.run('args \'*\' *', shell=True)" C:> wsl bash --login
$ deno -V
deno 1.8.1
$ deno run -A https://deno.land/x/dxx@v0.0.2/eg/args.ts '*' *
Download https://deno.land/x/dxx@v0.0.2/eg/args.ts
Check https://deno.land/x/dxx@v0.0.2/eg/args.ts
* CHANGELOG.mkd LICENSE README.md eg src tests tools tsconfig.json All of these invocations are parsed correctly and have the same output. And I think the utility is obvious. Command line tools which are called and work the same between platforms? And how many times have you wanted to pass some unusual string construction to a Windows command tool? This makes most constructions simple, even passing control characters. I haven't had the time to test MSYS or Cygwin (mostly just to install
This is hyperbole; "all windows software ..." is untrue. I've given specific counter examples.
No, single quotes are not an issue. But this is partially true in ways unrelated to single quotes. Assuming this is run from the CMD shell, the only thing unretrievably 'mogrified' in your example is the This can be done, as I have here, without Deno support. But it involves more code contortions, especially for sub-processes. I believe it would be simpler if Deno could just provide the raw text that it parses for |
So I did a quick test: [getcmd.c source code]
So the actual command line that It seems that msys/ does something similar, and people love it: msys2/msys2-runtime#36 msys2/MSYS2-packages#522 git-for-windows/git#1220 curl/curl#1813 magit/magit#2246 magit/magit#2246 magit/magit#2711 git-for-windows/git#561 git-for-windows/git#1019 |
So, PowerShell is currently a special child going through many growing pains, one of which is command line argument passing (see PowerShell/PowerShell#13089 and PowerShell/PowerShell#15143). That's one of the reasons why, to a large extent, most applications will use But, generally, using the For *nix/POSIX shells, you should be using an executable built for that system (which would then know to leave the command line alone), eg, use *nix/POSIX executables under wsl/bash. That's what the rust executables that I mentioned are designed to do. And that's why the command What does To be clear, I'm not asking for Deno to process the command line, just asking for it to be supplied so that a script can do as all current regular Windows executables can do ... process the raw command line if they want to (preferably through a well tested library). The prototype just shows that a lot can be done to make the scripts more useful and flexible at the command line for users. Wouldn't you like to be able to use bash-like expansion, globs, etc from the Windows command line? I, personally, frequently miss it when I switch from |
Talking beyond the ask here, but, after thinking about your points, I was able to test my prototype further under MSYS and WSL. Based on that testing and the discussion, I made some modifications to add shell detection (via
deno install -Af https://deno.land/x/dxx@v0.0.4/src/dxi.ts
dxi -Af https://deno.land/x/dxx@v0.0.4/eg/args.ts
args --debug '*' "*" * END Direct execution of the bash/sh shell shim script works as long as WSLENV=$WSLENV:SHELL/w deno.exe run -A https://deno.land/x/dxx@v0.0.4/eg/args.ts '*' "*" * END I'm not sure how to (or if there's a way) to detect the passthru execution of |
I'm not sure what you're trying to say here... But if you're implying that I'm not sure that the referenced code (issue, discussion, commit) is directly relevant, but it does show that there is significant nuance and complexity to the problem of reading, creating, and using command line arguments for Windows. |
Duplicate of #8852? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Not stale. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Not stale. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Not stale. |
I spent a long time trying to get a command that looks like |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Not stale. |
This is not true, if you check the David Deley’s closest-to-authoritative document on Windows command-line parsing: https://daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULES. Specifically:
Deley does not address globbing, but I recommend reading the part quoted in remkop/picocli#1761 (comment). There used to be a trove of Java complaints around the time they updated their MS C++ runtime & switched the setting. That was less than 30 years ago.
This is also not totally wise. Among Windows programs, very few things give you access to the raw command-line as the main interface. Other things, from .NET Arguments, Python The point is: whatever extensions you bring in, it MUST NOT break dquoted msvcrt-style arguments. You still have the liberty of messing with unquoted things.
|
For Windows, CLI applications need access to the original command line to supply basic services that the Windows shells (CMD/PowerShell) do not, such as wildcard/glob expansion. For example:
In *nix (bash-shell):
The Windows versions:
You'll note that the information required to perform reasonable wildcard/glob expansion is removed in the
Deno.args
array. Specifically here, the quotes are removed, so there is no application-detectable difference between the two arguments. For *nix/bash, it doesn't matter as the shell does the expansion for the application and supplies those tailored arguments, but Windows applications are expected to do that work themselves. The only way to do that is to have access to the original, unparsed command line (such as viaGetCommandLineW
).The text was updated successfully, but these errors were encountered: