Skip to content

Commit 98f821c

Browse files
JonZeollaclaude
andcommitted
fix: write PowerShell installer to temp file instead of piping stdin
PowerShell's -Command - does not reliably read scripts from stdin, causing the zenable CLI installer to exit 0 without actually installing. Write the install.ps1 to a temp file and use -File instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 21da236 commit 98f821c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

hooks/post_gen_project.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import shutil
1212
import subprocess
1313
import sys
14+
import tempfile
1415
from collections import OrderedDict
1516
from logging import basicConfig, getLogger
1617
from pathlib import Path
@@ -205,25 +206,39 @@ def _install_zenable_binary() -> bool:
205206

206207
if sys.platform == "win32":
207208
installer_key = "install.ps1"
208-
cmd = ["powershell", "-ExecutionPolicy", "Bypass", "-Command", "-"]
209209
else:
210210
installer_key = "install.sh"
211-
cmd = ["bash"]
212211

213212
install_url = metadata["installers"][installer_key]
214213
expected_checksum = metadata["installer_checksums"][installer_key]
215214

216215
install_script = _download_url(install_url)
217216
_verify_checksum(install_script, expected_checksum)
218217

218+
if sys.platform == "win32":
219+
# Write to a temp file because PowerShell's -Command - does not
220+
# reliably read scripts from stdin.
221+
tmp = tempfile.NamedTemporaryFile(suffix=".ps1", delete=False, mode="wb")
222+
tmp.write(install_script)
223+
tmp.close()
224+
cmd = ["powershell", "-ExecutionPolicy", "Bypass", "-File", tmp.name]
225+
input_data = None
226+
else:
227+
cmd = ["bash"]
228+
input_data = install_script
229+
tmp = None
230+
219231
result = subprocess.run(
220232
cmd,
221-
input=install_script,
233+
input=input_data,
222234
check=True,
223235
capture_output=True,
224236
timeout=120,
225237
env=env,
226238
)
239+
240+
if tmp is not None:
241+
Path(tmp.name).unlink(missing_ok=True)
227242
if result.stdout:
228243
LOG.info("Zenable installer stdout: %s", result.stdout.decode("utf-8", errors="replace").strip())
229244
if result.stderr:

0 commit comments

Comments
 (0)