Giter VIP home page Giter VIP logo

Comments (12)

xilun avatar xilun commented on July 20, 2024

One problem is that Win32 escaping/splitting of the command line is not 100% standardized.
But I guess by default we could use the MSVC / CommandLineToArgvW way and add an option to stay raw.

from cbwin.

xilun avatar xilun commented on July 20, 2024

Update: when we go through cmd.exe we must also take into account its own parsing rules to do proper escaping.

from cbwin.

goreliu avatar goreliu commented on July 20, 2024

I didn't add quotes to the first argument(command), so wrun/wcmd/wstart 'anything' is OK. When we want to use cmd.exe's parsing rules, can run with wrun/wcmd/wstart 'anything', just 1 argument.

Examples:

# 2 arguments, 1: aa bb 2: cc
$ wcmd echo "aa bb" cc
"aa bb" "cc"

# 3 arguments, 1:aa 2:bb 3: cc
$ wcmd echo aa bb cc
"aa" "bb" "cc"

# I don't kown how many arguments there are, pass the string to cmd.exe(or other softwares). Some softwares think `aa bb cc` is 1 argument, others think there are 3 arguments, I don't care.
$ wcmd 'echo aa bb cc'
aa bb cc

from cbwin.

xilun avatar xilun commented on July 20, 2024

This is slightly more tricky than it looks like at first, for example for now with no quoting/escaping at all:

$ wcmd  "foo&bar" 2000
'foo' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
'bar' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.

A reasonable expectation if we handle quoting and escaping would be that an attempt to run e.g. foo&bar.exe is performed instead of that, but & is interpreted by cmd, so when using cmd we should escape some characters. Then if we do so, the behavior if we remove the "2000" param should not be drastically different.

from cbwin.

goreliu avatar goreliu commented on July 20, 2024

If someone run wcmd "foo&bar" 2000, I don't think wcmd should convert foo&bar to foo^&bar, because wcmd "foo&bar" seems same with wcmd "dir&pause". He didn't tell wcmd that foo&bar is a filename. He should run wcmd "foo^&bar" if he has a foo&bar.exe.

But if I want to edit dir&pause with notepad, I will type wcmd notepad "dir&pause". If I want to edit dir with notepad and run pause, I will type wcmd 'notepad dir&pause'. It works well.

from cbwin.

goreliu avatar goreliu commented on July 20, 2024

Now:

wcmd a b c    ->    run:cmd /C a b c
wcmd a "b c"    ->    run:cmd /C a b c    # same with wcmd a b c
wcmd a '"b c"'    ->    run:cmd /C a "b c"
wcmd '"a"' '"b"' '"c"'    ->    run:cmd /C "a" "b" "c"
wcmd '"a"' b c    ->    run:cmd /C "a" b c

A better way:

wcmd a b c    ->    run:cmd /C a "b" "c"
wcmd 'a b c'    ->    run:cmd /C a b c
wcmd a "b c"    ->    run:cmd /C a "b c"
wcmd '"a"' b c    ->    run:cmd /C "a" "b" "c"
wcmd '"a" b c'    ->    run:cmd /C "a" b c

And so we shouldn't add " to a(1st argument).

from cbwin.

xilun avatar xilun commented on July 20, 2024

A problem with never quoting/escaping the first param at all is also that e.g. wcmd "c:\Program Files (x86)\Notepad++\notepad++.exe" bla.txt would not work, while oddly wcmd echo toto \& "c:\Program Files (x86)\Notepad++\notepad++.exe" would. I'm looking for something consistent...

from cbwin.

goreliu avatar goreliu commented on July 20, 2024

wcmd '"c:\Program Files (x86)\Notepad++\notepad++.exe" bla.txt' works.

from cbwin.

xilun avatar xilun commented on July 20, 2024

But then you can't have your filenames you want to edit escaped, and the double escaping just for the (first) program is nasty.
Actually I did a mistake wcmd echo toto \& "c:\Program Files (x86)\Notepad++\notepad++.exe" bla.txt would not launch notepad++ because the '&' would be escaped from cmd.
But then I must also think about #27: wstart'ing urls is a big use case and while #27 uses c:/progra~2/opera/launcher.exe it is actually possible to do wstart http://www.google.com/ (<- (edit:) I did not know that was possible), except that for now it fails when you have a '&' in the url, which is quite common.

edit: more precise about what I did not know was possible :)

from cbwin.

xilun avatar xilun commented on July 20, 2024

So for now I more in favor of the general idea of quoting and escaping everything if needed, and nothing if doing for example: wcmd --raw 'notepad&pause', but I'll still think about it a bit before I implement anything.

from cbwin.

goreliu avatar goreliu commented on July 20, 2024

The first parameter of start is ["title"]:

> start "a b.txt"
( Open a cmd.exe window with the title "a b.txt"
> start "" "a b.txt"
(Open "a b.txt" file)

So wstart '""' '"a b.txt"' and wstart "" '"http://example.com/?a=1&b=2"' works.

If I modify the code like this:

@@ -958,14 +975,15 @@ int main(int argc, char *argv[])
         string_append(&outbash_command, "\nrun:cmd /C ");
         break;
     case TOOL_WSTART:
-        string_append(&outbash_command, "\nrun:cmd /C start ");
+        string_append(&outbash_command, "\nrun:cmd /C start \"\" \"");
         break;
     }

     bool sep = false;
     for (int i = 0; i < argc; i++) {
-        if (sep) string_append(&outbash_command, " ");
+        if (sep) string_append(&outbash_command, " \"");
         string_append(&outbash_command, argv[i]);
+        if (sep || tool == TOOL_WSTART) string_append(&outbash_command, "\"");
         sep = true;
     }
     string_append(&outbash_command, "\n\n");

wstart "a b.txt" and wstart "http://example.com/?a=1&b=2" works.

from cbwin.

xilun avatar xilun commented on July 20, 2024

The first parameter of start is ["title"]

Yes, only with quotes though, and most of the time useless anyway; except when launching a command line program that does not changes the console title itself. So I plan to give it, at least by default, the same thing as the command. Also, its escaping rules are yet another time different (wtf...)
Or maybe I could avoid all that insanity, well more probably only trade it for another, and use ShellExecute for wstart.

from cbwin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.