choco
choco copied to clipboard
Make refreshenv.bat error if powershell.exe is being used
If someone has the powershell profile installed, they would never call this as refreshenv is an alias for Update-SessionEnvironment.
This is quite difficult to determine. I found https://stackoverflow.com/a/16376399/18475, but it won't work if you drop from PowerShell.exe to cmd.exe to run commands, and I haven't found a way to capture the current title and set it back yet.
It also doesn't determine the difference between cmd started up just to run a batch and a long term child process of cmd.exe that you get if you open PowerShell and then drop into cmd.exe (call cmd.exe in PowerShell opens a child process). The script found can not tell the difference between the two.
I think I've solved this problem: beatcracker/choco@9e0d484 . Unfortunately I don't feel like signing CLA. Could you use my solution if I to release it separetely with some very permissive license (WTFPL or something like that)?
@beatcracker how will this work if say I'm in powershell.exe and then call cmd.exe to go into that prompt before calling refreshenv?
Looks like it could work. Don't feel like signing the CLA or are unable to?
how will this work if say I'm in powershell.exe and then call cmd.exe to go into that prompt before calling refreshenv?
It will refresh env. vars inside that cmd session. But if you run it as RefreshEnv.cmd from PS console it will show the warning. I've tested this in both PS console and ISE.
Don't feel like signing the CLA or are unable to?
Don't feel like. It requires sharing my personal data and this is something I'm very reluctant to do. Sorry about that.
It requires sharing my personal data and this is something I'm very reluctant to do.
Understood. It probably won't help, but the data goes nowhere. We don't share it with anyone.
Set up something generic in a repository and give it a very permissive license. Then we can take a closer look.
Set up something generic in a repository and give it a very permissive license. Then we can take a closer look.
Sure, will MIT be suitable?
MIT is perfect.
Done: https://github.com/beatcracker/detect-batch-subshell
So I took the sample code from @beatcracker for a spin (as well as previously having done some investigating on this myself). I had hoped to use a separate file that could be fully attributed to beatcracker, but it appears that's not possible (if you call the cmd from within a cmd, it detects as being run interactively 😅 ).
I have a bit of work to do to get it ready for a PR, but should have a PR up for this by the end of the month 😄
@vexx32 can you update this issue with the milestone is this work intended to go out on?