<commit_before>package libbusyna

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
)

// strace runner: ############################################################

// StraceRun runs a command using strace and writes the trace information to
// the returned channel.
// The environment variables and working directory can be specified.
// Returns a channel that receives the strace output, line-by-line.
func StraceRun(command string, env map[string]string, dir string) <-chan string {
	// Create a tmp file with the command, that removes itself at the end.
	cmdfile, err := ioutil.TempFile("", "busyna-strace-cmdfile-")
	cmdfile.WriteString(command)
	cmdfile.WriteString(fmt.Sprint("\n\n\nrm -f ", cmdfile.Name(), "\n"))

	// Create a tmp file for strace output.
	straceout, err := ioutil.TempFile("", "busyna-strace-output-")
	if err != nil {
		log.Fatal(err)
	}
	defer TmpEnd(straceout)

	// env2 will have the environment as expected by exec.Cmd
	var env2 []string
	if env == nil {
		env2 = nil
	} else {
		for k, v := range env {
			env2 = append(env2, fmt.Sprint(k, "=", v))
		}
	}

	// Build strace command-line and call it
	a := []string{
		"strace",
		"-f",
		"-a0",
		"-s1024",
		"-etrace=execve,clone,vfork,chdir,creat,rename,mkdir,rmdir,open",
		"-o" + straceout.Name(),
		"/bin/sh",
		cmdfile.Name(),
	}

	p, err := exec.LookPath("strace")
	if err != nil {
		log.Fatal(err)
	}

	cmd := exec.Cmd{
		Path:   p,
		Args:   a,
		Stdout: os.Stdout,<commit_msg>StraceRun: do not remove the standard environment if a new is set<commit_after>package libbusyna

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
)

// strace runner: ############################################################

// StraceRun runs a command using strace and writes the trace information to
// the returned channel.
// The environment variables and working directory can be specified.
// Returns a channel that receives the strace output, line-by-line.
func StraceRun(command string, env map[string]string, dir string) <-chan string {
	// Create a tmp file with the command, that removes itself at the end.
	cmdfile, err := ioutil.TempFile("", "busyna-strace-cmdfile-")
	cmdfile.WriteString(command)
	cmdfile.WriteString(fmt.Sprint("\n\n\nrm -f ", cmdfile.Name(), "\n"))

	// Create a tmp file for strace output.
	straceout, err := ioutil.TempFile("", "busyna-strace-output-")
	if err != nil {
		log.Fatal(err)
	}
	defer TmpEnd(straceout)

	// env2 will have the environment as expected by exec.Cmd
	var env2 []string
	if env == nil {
		env2 = nil
	} else {
		for _, kv := range os.Environ() {
			env2 = append(env2, kv)
		}
		for k, v := range env {
			env2 = append(env2, fmt.Sprint(k, "=", v))
		}
	}

	// Build strace command-line and call it
	a := []string{
		"strace",
		"-f",
		"-a0",
		"-s1024",
		"-etrace=execve,clone,vfork,chdir,creat,rename,mkdir,rmdir,open",
		"-o" + straceout.Name(),
		"/bin/sh",
		cmdfile.Name(),
	}

	p, err := exec.LookPath("strace")
	if err != nil {
		log.Fatal(err)
	}

	cmd := exec.Cmd{
		Path:   p,
		Args:   a,
		Stdout: os.Stdout,
{'fraction_non_alphanumeric': 0.18665407617248977, 'fraction_numerical': 0.006924771797293044, 'mean_word_length': 3.5530085959885387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6575313', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1164, 'n_words': 327}