|
11 | 11 | import sys, subprocess, json, os, asyncio, functools
|
12 | 12 | from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
13 | 13 | import pandas as pd
|
14 |
| -import tempfile |
| 14 | +import tempfile, shlex |
15 | 15 |
|
16 | 16 | from io import StringIO
|
17 | 17 |
|
@@ -205,8 +205,9 @@ def _run_query(self, query, custom_auth=None, env_vars=None):
|
205 | 205 | :raises FileNotFoundError: If the StackQL binary isn't found.
|
206 | 206 | :raises Exception: For any other exceptions during the execution, providing a generic error message.
|
207 | 207 | """
|
| 208 | + |
208 | 209 | local_params = self.params.copy()
|
209 |
| - local_params.insert(1, f'"{query}"') |
| 210 | + local_params.insert(1, shlex.quote(query)) |
210 | 211 | script_path = None
|
211 | 212 |
|
212 | 213 | # Handle custom authentication if provided
|
@@ -240,19 +241,32 @@ def _run_query(self, query, custom_auth=None, env_vars=None):
|
240 | 241 | full_command = " ".join([self.bin_path] + local_params)
|
241 | 242 |
|
242 | 243 | try:
|
243 |
| - with subprocess.Popen(full_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as iqlPopen: |
244 |
| - stdout, stderr = iqlPopen.communicate() |
245 |
| - |
246 |
| - if self.debug: |
247 |
| - self._debug_log(f"query: {query}") |
248 |
| - self._debug_log(f"stdout: {stdout}") |
249 |
| - self._debug_log(f"stderr: {stderr}") |
250 |
| - |
251 |
| - # Process stdout and stderr |
252 |
| - if stderr: |
253 |
| - output["error"] = stderr.decode('utf-8') if isinstance(stderr, bytes) else str(stderr) |
254 |
| - if stdout: |
255 |
| - output["data"] = stdout.decode('utf-8') if isinstance(stdout, bytes) else str(stdout) |
| 244 | + |
| 245 | + full_command = full_command.replace("\n", " ") |
| 246 | + |
| 247 | + result = subprocess.run( |
| 248 | + full_command, |
| 249 | + shell=True, |
| 250 | + text=True, |
| 251 | + capture_output=True |
| 252 | + ) |
| 253 | + |
| 254 | + stdout = result.stdout |
| 255 | + stderr = result.stderr |
| 256 | + returncode = result.returncode |
| 257 | + |
| 258 | + if self.debug: |
| 259 | + self._debug_log(f"fullcommand: {full_command}") |
| 260 | + self._debug_log(f"returncode: {returncode}") |
| 261 | + self._debug_log(f"stdout: {stdout}") |
| 262 | + self._debug_log(f"stderr: {stderr}") |
| 263 | + |
| 264 | + # Process stdout and stderr |
| 265 | + if stderr: |
| 266 | + output["error"] = stderr.decode('utf-8') if isinstance(stderr, bytes) else str(stderr) |
| 267 | + if stdout: |
| 268 | + output["data"] = stdout.decode('utf-8') if isinstance(stdout, bytes) else str(stdout) |
| 269 | + |
256 | 270 |
|
257 | 271 | except FileNotFoundError:
|
258 | 272 | output["exception"] = f"ERROR: {self.bin_path} not found"
|
|
0 commit comments