fix(client): use powershell -NoProfile as executor to prevent $PROFILE clear

This commit is contained in:
Helios Agent 2026-03-03 14:59:09 +01:00
parent 0e8f2b11e8
commit ccf585f801
No known key found for this signature in database
GPG key ID: C8259547CD8309B5

View file

@ -1,6 +1,6 @@
/// Shell execution — each command runs in its own fresh process.
/// No persistent state, no sentinel logic, no encoding tricks.
/// stdout/stderr are captured as raw bytes and decoded with from_utf8_lossy.
/// On Windows we use powershell.exe -NoProfile so the user's $PROFILE
/// (which might run `clear`) is never loaded.
use std::time::Duration;
use tokio::process::Command;
@ -14,10 +14,11 @@ impl PersistentShell {
pub async fn run(&mut self, command: &str) -> Result<(String, String, i32), String> {
#[cfg(windows)]
{
// /D = skip AutoRun registry (no user `clear` hooks)
// /C = run command and exit
let mut cmd = Command::new("cmd.exe");
cmd.args(["/D", "/C", command]);
// -NoProfile: skip $PROFILE (prevents user's `clear` from running)
// -NonInteractive: no prompts
// -Command: run the given command string
let mut cmd = Command::new("powershell.exe");
cmd.args(["-NoProfile", "-NonInteractive", "-Command", command]);
run_captured(cmd, Duration::from_millis(TIMEOUT_MS)).await
}
#[cfg(not(windows))]