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

ConEmu Interprets Its Own Command-Line Arguments in 3rd Party Scripts That Are Run in It #1354

Closed
Maximus5 opened this Issue Jul 31, 2015 · 25 comments

Comments

Projects
None yet
1 participant
@Maximus5
Owner

Maximus5 commented Jul 31, 2015

Originally reported on Google Code with ID 1354

OS version: Win7 x64
ConEmu version: 131107

*Bug description*
This is a stupid corner case which I don't know whether to qualify as a bug or as an
unintentional feature.

Imagine that you have a script (batch, python, etc.) which has to invoke some other
external utilities and pass them strings (as command-line arguments) which in turn
contain invocation of ConEmu with its typical command-line arguments, for instance,
`-new_console` and/or `-cur_console`.

One example would be some of my configuration scripts (python) which invoke `reg.exe`
and command it to create certain variables in the registry which would contain invocations
of ConEmu with certain command-line arguments, in particular `-new_console` and/or
`-cur_console`. I use these scripts for custom integration of ConEmu into the shell
`explorer.exe` context menus. So obviously the commands of ConEmu invocation with `-new_console`
and/or `-cur_console` arguments are somehow stored in strings of the script. Now, when
I call this script from the ConEmu itself (to perform the integration), and when the
script tries to call, for example, something like `reg.exe ... /t REG_EXPAND_SZ /d
"ConEmu.exe ... -new_console:n:cmd.exe ..." ...`, this, in fact, provokes ConEmu to
think that I run inside of it `ConEmu.exe ... -new_console:n:cmd.exe ...`, and instead
of doing what script should (adding an entry to registry), ConEmu breaks the script
and really opens a new console (in another tab), can you believe that?! This is such
a stupid corner case that at first I couldn't even believe it myself. Of course running
the script through bare `cmd.exe` or any other terminal works perfectly fine. The problem
is definitely ConEmu itself, and this should be absolutely fixed.

Reported by Haroogan on 2013-11-20 12:58:28

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
So many letters and nothing is clear...
Show minimalistic examples at least.
May be you trying to use args improperly...

Reported by ConEmu.Maximus5 on 2013-11-20 13:18:55

Owner

Maximus5 commented Jul 31, 2015

So many letters and nothing is clear...
Show minimalistic examples at least.
May be you trying to use args improperly...

Reported by ConEmu.Maximus5 on 2013-11-20 13:18:55

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
I don't know what's so hard to understand in this detailed description. If you can't
imagine it yourself, then I'll help you. Here's the very simplified version of the
script.

1. Understand what it does, it will change your registry (don't forget to clean-up
later);
2. You need administrator rights to run the script;
3. Don't forget to change the path to ConEmu executable (where it is located on your
system);
4. Run from bare `cmd.exe` or other terminal emulator, and see that the script does
what it should;
5. Run from ConEmu, and experience the annoying corner case, and see how the script
breaks.

Reported by Haroogan on 2013-11-20 17:40:21


- _Attachment: [test.py](https://storage.googleapis.com/google-code-attachments/conemu-maximus5/issue-1354/comment-2/test.py)_
Owner

Maximus5 commented Jul 31, 2015

I don't know what's so hard to understand in this detailed description. If you can't
imagine it yourself, then I'll help you. Here's the very simplified version of the
script.

1. Understand what it does, it will change your registry (don't forget to clean-up
later);
2. You need administrator rights to run the script;
3. Don't forget to change the path to ConEmu executable (where it is located on your
system);
4. Run from bare `cmd.exe` or other terminal emulator, and see that the script does
what it should;
5. Run from ConEmu, and experience the annoying corner case, and see how the script
breaks.

Reported by Haroogan on 2013-11-20 17:40:21


- _Attachment: [test.py](https://storage.googleapis.com/google-code-attachments/conemu-maximus5/issue-1354/comment-2/test.py)_
@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
I see sort of automation here, right? But how exactly do you run this script? Solutions
may differs...

Another question, why you are running ConEmuPortable.exe but not a ConEmu.exe?

Reported by ConEmu.Maximus5 on 2013-11-20 18:40:08

Owner

Maximus5 commented Jul 31, 2015

I see sort of automation here, right? But how exactly do you run this script? Solutions
may differs...

Another question, why you are running ConEmuPortable.exe but not a ConEmu.exe?

Reported by ConEmu.Maximus5 on 2013-11-20 18:40:08

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
I run these scripts and they install `explorer.exe` integration for me as I've already
stated. They integrate different `bash` versions and `cmd.exe` into context menus plus
all the combinations again but as administrator, so that I can conveniently open any
shell in ConEmu with user or administrator rights from any directory. But that's not
even my point here. This is just an example where I've detected a defect, it could
be any any other script, which happens to contain such strings with invocation of ConEmu,
but does not aim to call ConEmu directly.

I'm using portable version because I don't want ConEmu to write anything to the registry.
I inherently don't like installers and all of that kind. Portable software, when designed
properly, is much more safe, convenient, and easy to use.

Reported by Haroogan on 2013-11-21 02:43:25

Owner

Maximus5 commented Jul 31, 2015

I run these scripts and they install `explorer.exe` integration for me as I've already
stated. They integrate different `bash` versions and `cmd.exe` into context menus plus
all the combinations again but as administrator, so that I can conveniently open any
shell in ConEmu with user or administrator rights from any directory. But that's not
even my point here. This is just an example where I've detected a defect, it could
be any any other script, which happens to contain such strings with invocation of ConEmu,
but does not aim to call ConEmu directly.

I'm using portable version because I don't want ConEmu to write anything to the registry.
I inherently don't like installers and all of that kind. Portable software, when designed
properly, is much more safe, convenient, and easy to use.

Reported by Haroogan on 2013-11-21 02:43:25

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Again. ConEmu.exe its portable from the box! No need in ConEmuPortable.exe, it was created
only for PortableApps.com.
Just unpack ConEmuPack.7z and enjoy.

You may skip "-new_console" processing. Just ensure, that process which creates new
process does not hooked.
For example. You are in cmd.exe prompt on ConEmu tab. Your cmd.exe is hooked (usually)
and it process new_console.
But, if you call, for example
cmd.exe -cur_console:i /c your_script.cmd
You will gain ability (in your_script.cmd) to create processes with -new_console switches
without preprocessing.

Reported by ConEmu.Maximus5 on 2013-11-21 07:14:24

Owner

Maximus5 commented Jul 31, 2015

Again. ConEmu.exe its portable from the box! No need in ConEmuPortable.exe, it was created
only for PortableApps.com.
Just unpack ConEmuPack.7z and enjoy.

You may skip "-new_console" processing. Just ensure, that process which creates new
process does not hooked.
For example. You are in cmd.exe prompt on ConEmu tab. Your cmd.exe is hooked (usually)
and it process new_console.
But, if you call, for example
cmd.exe -cur_console:i /c your_script.cmd
You will gain ability (in your_script.cmd) to create processes with -new_console switches
without preprocessing.

Reported by ConEmu.Maximus5 on 2013-11-21 07:14:24

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Again. ConEmu.exe its portable from the box! No need in ConEmuPortable.exe, it was created
only for PortableApps.com.
Just unpack ConEmuPack.7z and enjoy.

You may skip "-new_console" processing. Just ensure, that process which creates new
process does not hooked.
For example. You are in cmd.exe prompt on ConEmu tab. Your cmd.exe is hooked (usually)
and it process new_console.
But, if you call, for example
cmd.exe -cur_console:i /c your_script.cmd
You will gain ability (in your_script.cmd) to create processes with -new_console switches
without preprocessing.

Reported by ConEmu.Maximus5 on 2013-11-21 07:14:31

Owner

Maximus5 commented Jul 31, 2015

Again. ConEmu.exe its portable from the box! No need in ConEmuPortable.exe, it was created
only for PortableApps.com.
Just unpack ConEmuPack.7z and enjoy.

You may skip "-new_console" processing. Just ensure, that process which creates new
process does not hooked.
For example. You are in cmd.exe prompt on ConEmu tab. Your cmd.exe is hooked (usually)
and it process new_console.
But, if you call, for example
cmd.exe -cur_console:i /c your_script.cmd
You will gain ability (in your_script.cmd) to create processes with -new_console switches
without preprocessing.

Reported by ConEmu.Maximus5 on 2013-11-21 07:14:31

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Anyway, did you try the script? Do you confirm the defect? If not, then please explain
what was the reasoning to allow ConEmu interpet private script environment by default?

Reported by Haroogan on 2013-11-21 10:40:44

Owner

Maximus5 commented Jul 31, 2015

Anyway, did you try the script? Do you confirm the defect? If not, then please explain
what was the reasoning to allow ConEmu interpet private script environment by default?

Reported by Haroogan on 2013-11-21 10:40:44

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
No need to try it. I've asked about command line only, and see it in your script.

Private? Really? How arguments if spawned processes may be "private"?

When you create new process in the ConEmu tab, REGARDLESS of way of execution, ConEmu
MUST process all new_console/cur_console arguments.
There is no other way to create new tab or change parameters of the current one!
Why do you think different?


Reported by ConEmu.Maximus5 on 2013-11-21 10:49:53

Owner

Maximus5 commented Jul 31, 2015

No need to try it. I've asked about command line only, and see it in your script.

Private? Really? How arguments if spawned processes may be "private"?

When you create new process in the ConEmu tab, REGARDLESS of way of execution, ConEmu
MUST process all new_console/cur_console arguments.
There is no other way to create new tab or change parameters of the current one!
Why do you think different?


Reported by ConEmu.Maximus5 on 2013-11-21 10:49:53

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
We probably misunderstand each other here. I don't want to create a new tab. Do you
realize that? The purpose of the script is to pass a string into the registry by invoking
`reg.exe` subprocess - that's it. Why if I run my my private (3rd party) script in
the shell that is open ConEmu, ConEmu tries to tamper with the contents of my private
(3rd party) script, break it, and draw certain implications for itself?

Reported by Haroogan on 2013-11-21 10:54:28

Owner

Maximus5 commented Jul 31, 2015

We probably misunderstand each other here. I don't want to create a new tab. Do you
realize that? The purpose of the script is to pass a string into the registry by invoking
`reg.exe` subprocess - that's it. Why if I run my my private (3rd party) script in
the shell that is open ConEmu, ConEmu tries to tamper with the contents of my private
(3rd party) script, break it, and draw certain implications for itself?

Reported by Haroogan on 2013-11-21 10:54:28

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Well, have considered of "-cur_console:-" switch, which will stop further processing
of ConEmu's internal switches (leaving them in creating process command line), but
it is very unpredictable... If you have not checked that ConEmu hooks are ON in the
current process, arguments may be written in registry unchanged (in your case), and
ConEmu GUI will not process new_console/cur_console switches, because of "-"...

Reported by ConEmu.Maximus5 on 2013-11-21 10:56:01

Owner

Maximus5 commented Jul 31, 2015

Well, have considered of "-cur_console:-" switch, which will stop further processing
of ConEmu's internal switches (leaving them in creating process command line), but
it is very unpredictable... If you have not checked that ConEmu hooks are ON in the
current process, arguments may be written in registry unchanged (in your case), and
ConEmu GUI will not process new_console/cur_console switches, because of "-"...

Reported by ConEmu.Maximus5 on 2013-11-21 10:56:01

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
OK, which hook tells ConEmu to interpret the contents of 3rd party scripts? How to disable
it?

Reported by Haroogan on 2013-11-21 11:00:35

Owner

Maximus5 commented Jul 31, 2015

OK, which hook tells ConEmu to interpret the contents of 3rd party scripts? How to disable
it?

Reported by Haroogan on 2013-11-21 11:00:35

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
You don't want, others does. Why ConEmu must not interpret its own arguments when user
creates process in console?

-new_console and -cur_console arguments are arguments of console part!
If one runs from shell "cmd -new_console" it MUST starts in NEW tab. That is by design.
Moreover, if one runs that command from script, it must runs in NEW tab too.

Reported by ConEmu.Maximus5 on 2013-11-21 11:09:38

Owner

Maximus5 commented Jul 31, 2015

You don't want, others does. Why ConEmu must not interpret its own arguments when user
creates process in console?

-new_console and -cur_console arguments are arguments of console part!
If one runs from shell "cmd -new_console" it MUST starts in NEW tab. That is by design.
Moreover, if one runs that command from script, it must runs in NEW tab too.

Reported by ConEmu.Maximus5 on 2013-11-21 11:09:38

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Read comment #6. It explains thoroughly how to do it.

Reported by ConEmu.Maximus5 on 2013-11-21 11:10:38

Owner

Maximus5 commented Jul 31, 2015

Read comment #6. It explains thoroughly how to do it.

Reported by ConEmu.Maximus5 on 2013-11-21 11:10:38

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
All good, but you break 3rd party scripts. It means that now whenever somebody's script
spawns other processes and passes to them strings which for whatever reason might contain
subsequences of `-cur_console` or `-new_console` - the script will be broken and would
be nonfunctional inside shell which is run by ConEmu terminal because ConEmu wants
sniff what's none of his business.

Reported by Haroogan on 2013-11-21 11:14:56

Owner

Maximus5 commented Jul 31, 2015

All good, but you break 3rd party scripts. It means that now whenever somebody's script
spawns other processes and passes to them strings which for whatever reason might contain
subsequences of `-cur_console` or `-new_console` - the script will be broken and would
be nonfunctional inside shell which is run by ConEmu terminal because ConEmu wants
sniff what's none of his business.

Reported by Haroogan on 2013-11-21 11:14:56

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
I'm also pretty sure that others simply don't know about that "nasty feature" yet because
it's quite rare that you can hit that problem. I'm sure people will be pissed that
your terminal breaks the private code which is run in it.

Reported by Haroogan on 2013-11-21 11:16:12

Owner

Maximus5 commented Jul 31, 2015

I'm also pretty sure that others simply don't know about that "nasty feature" yet because
it's quite rare that you can hit that problem. I'm sure people will be pissed that
your terminal breaks the private code which is run in it.

Reported by Haroogan on 2013-11-21 11:16:12

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
-cur_console and -new_console ARE INTERNAL switches, that ARE RESERVED for ConEmu!
Even you - trying to use them with ConEmu targeting.
Just trying to use them completely improperly!

Reported by ConEmu.Maximus5 on 2013-11-21 11:25:16

  • Status changed: Invalid
Owner

Maximus5 commented Jul 31, 2015

-cur_console and -new_console ARE INTERNAL switches, that ARE RESERVED for ConEmu!
Even you - trying to use them with ConEmu targeting.
Just trying to use them completely improperly!

Reported by ConEmu.Maximus5 on 2013-11-21 11:25:16

  • Status changed: Invalid
@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
-cur_console and -new_console ARE INTERNAL switches, that ARE RESERVED for ConEmu!
Even you - trying to use them with ConEmu targeting.
Just trying to use them completely improperly!

Reported by ConEmu.Maximus5 on 2013-11-21 11:25:26

Owner

Maximus5 commented Jul 31, 2015

-cur_console and -new_console ARE INTERNAL switches, that ARE RESERVED for ConEmu!
Even you - trying to use them with ConEmu targeting.
Just trying to use them completely improperly!

Reported by ConEmu.Maximus5 on 2013-11-21 11:25:26

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Furthermore, why should I protect 3rd party scripts with some awkward constructs like
`cmd.exe -cur_console:i /c your_script.cmd` just so that the all mighty ConEmu does
not break them? I think you better off doing it the other way around, i.e. by default
ConEmu should not sniff what's going on in 3rd party scripts, and only if somebody
has written a script which is somehow related to ConEmu, i.e. contains all these switches
which are intended for interpretation by ConEmu, then one must use awkward constructs
like `cmd.exe -cur_console:i /c your_script.cmd` to execute such a script.

Reported by Haroogan on 2013-11-21 11:26:15

Owner

Maximus5 commented Jul 31, 2015

Furthermore, why should I protect 3rd party scripts with some awkward constructs like
`cmd.exe -cur_console:i /c your_script.cmd` just so that the all mighty ConEmu does
not break them? I think you better off doing it the other way around, i.e. by default
ConEmu should not sniff what's going on in 3rd party scripts, and only if somebody
has written a script which is somehow related to ConEmu, i.e. contains all these switches
which are intended for interpretation by ConEmu, then one must use awkward constructs
like `cmd.exe -cur_console:i /c your_script.cmd` to execute such a script.

Reported by Haroogan on 2013-11-21 11:26:15

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Damn... There is no way to DETECT that it is "third party script" as you said. User
must think what he doing...

Reported by ConEmu.Maximus5 on 2013-11-21 11:28:48

Owner

Maximus5 commented Jul 31, 2015

Damn... There is no way to DETECT that it is "third party script" as you said. User
must think what he doing...

Reported by ConEmu.Maximus5 on 2013-11-21 11:28:48

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
You don't have to detect anything - just stop interpreting `-cur_console` and `-new_console`
BY DEFAULT in the shell.

Reported by Haroogan on 2013-11-21 11:30:52

Owner

Maximus5 commented Jul 31, 2015

You don't have to detect anything - just stop interpreting `-cur_console` and `-new_console`
BY DEFAULT in the shell.

Reported by Haroogan on 2013-11-21 11:30:52

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Stop one if the most decent and powerful ConEmu feature? You are kidding...

Reported by ConEmu.Maximus5 on 2013-11-21 11:39:21

Owner

Maximus5 commented Jul 31, 2015

Stop one if the most decent and powerful ConEmu feature? You are kidding...

Reported by ConEmu.Maximus5 on 2013-11-21 11:39:21

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
OK, I'm the user of ConEmu - your user. And I'm telling you, that I don't want commands
like `git "-new_console:C:cmd.exe"` to be hooked by ConEmu by default because I just
wanted to pass a string which contains that a subsequence `-new_console`. Why would
I want to do that? It's my business, and none of ConEmu. I'm not saying remove that
functionality, of course not. I'm saying either disable it by default, so that people
have less surprises, or give us a checkbox to toggle it. Those who need it on daily
basis, will turn it on, those who don't, will turn it off, and it's better be turned
off by default.

Reported by Haroogan on 2013-11-21 11:57:11

Owner

Maximus5 commented Jul 31, 2015

OK, I'm the user of ConEmu - your user. And I'm telling you, that I don't want commands
like `git "-new_console:C:cmd.exe"` to be hooked by ConEmu by default because I just
wanted to pass a string which contains that a subsequence `-new_console`. Why would
I want to do that? It's my business, and none of ConEmu. I'm not saying remove that
functionality, of course not. I'm saying either disable it by default, so that people
have less surprises, or give us a checkbox to toggle it. Those who need it on daily
basis, will turn it on, those who don't, will turn it off, and it's better be turned
off by default.

Reported by Haroogan on 2013-11-21 11:57:11

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Well, I'll create an option. But it well not be turned off by default. Breaking years
of experience? Never.

Reported by ConEmu.Maximus5 on 2013-11-21 12:42:32

  • Status changed: Accepted
Owner

Maximus5 commented Jul 31, 2015

Well, I'll create an option. But it well not be turned off by default. Breaking years
of experience? Never.

Reported by ConEmu.Maximus5 on 2013-11-21 12:42:32

  • Status changed: Accepted
@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner
Thank you. Appreciate your time. Keep up the good work! ;)

Reported by Haroogan on 2013-11-21 12:45:31

Owner

Maximus5 commented Jul 31, 2015

Thank you. Appreciate your time. Keep up the good work! ;)

Reported by Haroogan on 2013-11-21 12:45:31

@Maximus5

This comment has been minimized.

Show comment
Hide comment
@Maximus5

Maximus5 Jul 31, 2015

Owner

Reported by ConEmu.Maximus5 on 2013-12-02 23:49:44

  • Status changed: Fixed
Owner

Maximus5 commented Jul 31, 2015

Reported by ConEmu.Maximus5 on 2013-12-02 23:49:44

  • Status changed: Fixed

@Maximus5 Maximus5 closed this Jul 31, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment