Comments (12)
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.
Update: when we go through cmd.exe we must also take into account its own parsing rules to do proper escaping.
from cbwin.
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.
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.
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.
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.
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.
wcmd '"c:\Program Files (x86)\Notepad++\notepad++.exe" bla.txt'
works.
from cbwin.
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.
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.
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.
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)
- wrun: can't translate a WSL VolFs path to a Win32 one HOT 7
- Default command handler HOT 10
- some win32 console programs "sometimes" do line feed instead of new line, but a workaround seems possible HOT 1
- a cmd-like behavior distinguishing between console / GUI target programs might be useful HOT 1
- backgrounded & force redirected caller => SIGTTIN
- Problem with arguments containing the character "&" HOT 1
- wcmd cmd no longer laggy, but eats characters HOT 1
- Let cbwin in session mode launch multiple wcmd instances in parallel HOT 11
- sockets for redirections are not using any security HOT 6
- wstart /mnt/c/windows does not work HOT 7
- Not work inside zsh HOT 14
- behavior of environment variable inconsistent in regards to case sensitivity HOT 1
- No terminal support HOT 6
- Vagrant output doesn't wrap correctly HOT 4
- interactive win32 console programs are broken (input and output) HOT 5
- Native Windows support for launching Windows applications HOT 1
- Some inputted characters skipped in Docker interactive terminal HOT 1
- Starting parameters for bash.exe
- Can't remove cbwin from my pc HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cbwin.