shellingham | Tool to Detect Surrounding Shell
kandi X-RAY | shellingham Summary
kandi X-RAY | shellingham Summary
Tool to Detect Surrounding Shell
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Get a new process
- Iterate through all processes
- Determine the name of the interpreter
- Gets the full path of the full process image
- Determine the name of the login shell
- A context manager
- Iterate process arguments
- Get a shell
- Get process mapping
- Release the release
- Render the issue log file
- Write the package version
- Bump release by type
- Read git version from git
- Bump a version to the next version
- Returns a function that checks the last error
- Return a function that checks the handle of the handle
shellingham Key Features
shellingham Examples and Code Snippets
import ctypes, ctypes.wintypes, contextlib
k32 = ctypes.windll.kernel32
INVALID_HANDLE_VALUE = ctypes.wintypes.HANDLE(-1).value
ERROR_NO_MORE_FILES = 18
ERROR_INSUFFICIENT_BUFFER = 122
TH32CS_SNAPPROCESS = 2
PROCESS_QUERY_LIMITED_INFORMA
Community Discussions
Trending Discussions on shellingham
QUESTION
The following will return the shell that launched the current process & the shell's full path. However, it uses a python library full of c extensions. Sometimes a shell launches a shell, etc. I'm just looking for the "most recent ancestor" process that is a shell.
How do I do this with just pure python? (i.e. no c extensions, using windll.kernel32 and the like are fine- of course at some point to get process info code will have to access platform-specific native code, it just needs to be something already buried in the python standard library, not something that needs compiling c)
...ANSWER
Answered 2021-Jan-30 at 06:32The question is about looking for a way to walk the list of ancestor processes and find the first whose executable matches an item in a hardcoded list of names, hoping that it will be the user’s ‘shell’. Before I answer it, here are some reasons why this is an absolutely stupid and useless thing to do:
- The executable you are looking for may be named something else from what you expect. In a comment to the question I gave an example of naming the Bash executable
shab.exe
, which the asker dismissed with the punchline of the well-known doctor joke (‘well, don’t do that then’) as the user trying to ‘hide’ their shell. But this can happen even without any ‘spiteful’ intent to ‘hide’ something on the user’s part. For example, the user may have several versions of Bash installed with different executable names (bash-4.00.exe
,gitbash.exe
, etc.), in order to test whether their scripts are compatible with all of them. Are you going to enumerate every single possible name in your code? Or are you going to match all executables withsh
in their name and cross fingers that there aren’t any false positives? - Conversely, just because an executable has the name you expect, it doesn’t mean it will have the behaviour you expect. This is even more true on Windows, where there isn’t really a standardised set of executable names that should always have specific, prescribed behaviour. And this is especially true if you indiscriminately lump programs like
cmd
,bash
,fish
andxonsh
together under the name of ‘shell’: these programs accept different syntaxes on their own command lines and within their respective scripting languages. Unless all you want to do is launch the shell for the user to interact with, you’re going to be looking for the specific kind of the shell – whether it’s a POSIX-compatible shell, a DOS-derived shell likecmd
or something else completely – in order to take advantage of its particular behaviours. Merely knowing that it’s ‘a shell’ doesn’t actually tell you anything useful. And let’s not forget that not all shells are even command lines – Windows Explorer is a shell, after all. - Even if executable names did line up perfectly, there is no way a hardcoded list is going to be exhaustive. The asker’s list already omits
tcmd
ortclsh
. I hear some crazy people use Python itself as a shell – who are you to stop them? If a new shell appears, it will have to be added as another entry in the list; let’s hope there is still someone who remembers where it is then. - Though let’s say for the sake of the argument that we’re only interested in command-line shells and ignore everything else. What if the script is launched from an Explorer process that was itself started from Bash? The script is going to ignore the Explorer process and pick Bash as the ‘shell’, even though it’s clearly Explorer and not Bash which launched the script. Is this correct or desired? I think the answer is far from obvious.
But if the above doesn’t deter you from this futile task (or perhaps you want to do something similar for a more sensible purpose), here’s how you can accomplish this nonsensical thing anyway:
QUESTION
I'm trying to install pendulum 2.0.5 in a python37-alpine based docker image but it gives me the below error:
...ANSWER
Answered 2019-Dec-18 at 17:11You need to install libffi-dev
and probably openssl-dev
as well (plus a C compiler if you don't have one available) because cffi
and cryptography
require these packages to compile against system libraries. Normally these packages have binary wheels available, but Alpine uses a different libc which is incompatible with the manylinux
specification so you'll have to compile it yourself.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install shellingham
You can use shellingham like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page