Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Created February 22, 2024 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.
Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.
Why?
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
func main() {
cmd := exec.Command("/opt/homebrew/bin/zsh")
// When I run this, I can't `ctrl-c` the program anymore:
cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0"}
// But if it's this, I can `ctrl-c`:
// cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0; exit 0"}
//
// Even if it's this:
// cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0; echo ROFLMAO"}
//
// WHY?!
//
// I just launch a subprocess that exits. How can it hijack my signal handling?
_, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
for {
time.Sleep(1 * time.Second)
fmt.Println("still running...")
}
}
use std::process::Command;
use std::thread;
use std::time::Duration;
fn main() {
let mut cmd = Command::new("/opt/homebrew/bin/zsh");
// When I run this, I can't `ctrl-c` the program anymore:
cmd.args(&["-l", "-i", "-c", "/usr/bin/env -0; echo lol"]);
// But if it's this, I can `ctrl-c`:
// cmd.args(&["-l", "-i", "-c", "/usr/bin/env -0; exit 0"]);
//
// WHY?!
//
// I just launch a subprocess that exits. How can it hijack my signal handling?
let output = cmd.output().expect("Failed to execute command");
println!("{}", String::from_utf8_lossy(&output.stdout));
println!("{}", String::from_utf8_lossy(&output.stderr));
loop {
thread::sleep(Duration::from_secs(1));
println!("still running...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment