horeah/PyCmd

Feature Request: Auto inject into cmd like clin whenever cmd is called.

Opened this issue · 3 comments

Is it possible to inject pycmd into a cmd instance when it is called like clink?
Thanks in advance.

The way PyCmd works is completely different from clink; I (for one) don't see how we could inject it automatically in a cmd instance (@Spavid04 might have an opinion here).

Why do you need this? What are you trying to achieve? There are probably decent workarounds for most use-cases...

I just had a quick look into clink, and the way they do is:

  • set a registry key at install time; that key specifies a command that cmd.exe calls every time, at startup
  • cmd.exe starts, and runs the clink "loader"
  • loader injects clink back into cmd.exe

I don't see this as a viable feature, at the very least until PyCmd is a complete cmd replacement, but PyCmd could allow being autorun in the same way.
I tried setting the AutoRun key on my machine, and starting cmd also starts an ""embedded"" PyCmd, but this stars an infinite loop, because the first thing to do is start a cmd. I guess this could be improved so at least users can set the AutoRun key themselves and not carpet bomb their system.
All in all I propose two changes: call nested cmd's with /D (that stops AutoRun from being called), and at startup check if the parent process is a bare cmd (ie strictly without any arguments) and exit if not. The second change might need some polish, though.

I think PyCmd is more "intrusive" than clink, and alters the behavior of some commands (e.g. cd works a bit differently, and so do quoting and escaping). For this reason, I would be wary about completely replacing cmd.exe with PyCmd; I would rather recommend tweaking the way(s) in which interactive sessions are being started, e.g. have the terminal application start PyCmd be default -- @ibay770 how are you typically starting your interactive command line sessions?

p.s. even running nested cmd's with /D sounds a bit risky, what if someone uses the AutoRun key to setup their environment (such as PATH, or who knows what else).