Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions crates/plugins/src/shell_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ impl HookHandler for ShellHookHandler {
"spawning shell hook"
);

let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(&self.command)
.envs(&self.env)
let mut cmd = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
c.arg("/C").arg(&self.command);
c
} else {
let mut c = Command::new("sh");
c.arg("-c").arg(&self.command);
c
};
Comment on lines +101 to +109
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 cmd.exe invoked without full path — prefer explicit binary name

Command::new("cmd") relies on cmd being resolvable via PATH. While cmd.exe is normally on the PATH on all Windows installations, using "cmd.exe" (with the .exe extension) is the Windows convention and avoids any edge-case ambiguity where a user might have a cmd script or binary earlier in their PATH.

Suggested change
let mut cmd = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
c.arg("/C").arg(&self.command);
c
} else {
let mut c = Command::new("sh");
c.arg("-c").arg(&self.command);
c
};
let mut cmd = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd.exe");
c.arg("/C").arg(&self.command);
c
} else {
let mut c = Command::new("sh");
c.arg("-c").arg(&self.command);
c
};

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

cmd.envs(&self.env)
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped());
Expand Down