MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / _spawn_proc

Function _spawn_proc

bbot/core/helpers/command.py:163–205  ·  view source on GitHub ↗

Spawns an asynchronous subprocess. Prepares the command and associated keyword arguments. If the `input` argument is provided, it checks to ensure that the `stdin` argument is not also provided. Once prepared, it creates and returns the subprocess. If the command executable is not found

(self, *command, **kwargs)

Source from the content-addressed store, hash-verified

161
162
163async def _spawn_proc(self, *command, **kwargs):
164 """Spawns an asynchronous subprocess.
165
166 Prepares the command and associated keyword arguments. If the `input` argument is provided,
167 it checks to ensure that the `stdin` argument is not also provided. Once prepared, it creates
168 and returns the subprocess. If the command executable is not found, it logs a warning and traceback.
169
170 Args:
171 *command (str): The command to run as separate arguments.
172 **kwargs (dict): Additional keyword arguments for the subprocess.
173
174 Raises:
175 ValueError: If both stdin and input arguments are provided.
176
177 Returns:
178 tuple: A tuple containing the created process (or None if creation failed), the input (or None if not provided),
179 and the prepared command (or None if subprocess creation failed).
180
181 Examples:
182 >>> _spawn_proc("ls", "-l", input="data")
183 (<Process ...>, "data", ["ls", "-l"])
184 """
185 try:
186 command, kwargs = self._prepare_command_kwargs(command, kwargs)
187 except SubprocessError as e:
188 command_str = " ".join([str(s) for s in command])
189 log.warning(f"Error running command: '{command_str}': {e}")
190 log.trace(traceback.format_exc())
191 return None, None, None
192 _input = kwargs.pop("input", None)
193 if _input is not None:
194 if kwargs.get("stdin") is not None:
195 raise ValueError("stdin and input arguments may not both be used.")
196 kwargs["stdin"] = asyncio.subprocess.PIPE
197
198 log.hugeverbose(f"run: {' '.join(command)}")
199 try:
200 proc = await asyncio.create_subprocess_exec(*command, **kwargs)
201 return proc, _input, command
202 except FileNotFoundError as e:
203 log.warning(f"{e} - missing executable?")
204 log.trace(traceback.format_exc())
205 return None, None, None
206
207
208async def _write_proc_line(proc, chunk):

Callers

nothing calls this directly

Calls 5

popMethod · 0.80
warningMethod · 0.45
traceMethod · 0.45
getMethod · 0.45
hugeverboseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…