Run a program Golang

I’m stuck on Stage #IP1.

I am trying to check if the “custom_exe_” exists in the command by doing a

strings.Contains(cmd, "custom_exe_")

but it returns a boolean value, which I can’t use because of the switch statement and cause cmd is a string
so how do I match it

Here are my logs:

[tester::#IP1] Running ./your_program.sh
[your-program] $ custom_exe_2902 Alice
[your-program] custom_exe_2902: command not found
[tester::#IP1] Output does not match expected value.
[tester::#IP1] Expected: "Program was passed 2 args (including program name)."
[tester::#IP1] Received: "custom_exe_2902: command not found"
[your-program] $ 
[tester::#IP1] Assertion failed.
[tester::#IP1] Test failed

And here’s a snippet of my code:

	for {
		fmt.Fprint(os.Stdout, "$ ")

		input, err := bufio.NewReader(os.Stdin).ReadString('\n')
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error reading input: ", err)
			os.Exit(1)
		}
		cmdArr := strings.Fields(input)
		cmd := cmdArr[0]

		if strings.TrimSpace(input) == "exit 0" {
			break
		}

		customExeExists := strings.Contains(cmd, "custom_exe_")

		switch cmd {
		case "echo":
			EchoCmd(cmdArr)
		case "type":
			TypeCmd(cmdArr)
		case customExeExists:
			CustomExeCmd(cmdArr)
		default:
			fmt.Println(strings.TrimSpace(cmd) + ": command not found")
		}
	}

Hey @logan1o1, strings.Contains isn’t the right fit here. You’ll need to reuse the PATH resolution logic from the previous stage #mg5 The type builtin: executable files.

If you’ve updated the code and would like me to take a look, feel free to upload your code to GitHub and share the link here. It’s much easier to help when I can run it directly.

Yeah, I got that, now I’m having a problem with submitting

@logan1o1 Could you share a screenshot showing the commands you ran along with the error messages?

Yeah, that was because I had accidentally turned off my wifi. Stupid stuff, sry if it wasted ur time

1 Like