Monday, October 2, 2023
HomeGolangDealing with error whereas attempting to get entry to enter file in...

Dealing with error whereas attempting to get entry to enter file in golang – Getting Assist

I’m new to golang and in an effort to full a coding problem I’ve downloaded a code snippet and i’ve gone by the file and after operating run.bat command as said within the file an executable file geektrust.exe is created however when I’m attempting to run the code by giving command go run major.go together with together with file path ./geektrust sample_input/input1.txt, it’s all the time printing an error message “Error opening the enter file”. On your reference I’m offering you the supply code file, file Observe:- the enter file has the extension .txt, it’s a textual content file


package deal major

import (

func major() {
    cliArgs := os.Args[1:]

    if len(cliArgs) == 0 {
        fmt.Println("Please present the enter file path")


    filePath := cliArgs[0]
    file, err := os.Open(filePath)

    if err != nil {
        fmt.Println("Error opening the enter file")


    defer file.Shut()
    scanner := bufio.NewScanner(file)

    for scanner.Scan() {
            args := scanner.Textual content()
            argList := strings.Fields(args)

            Add your code right here to course of the enter instructions

} file

# Pre-requisites
* Go 1.15.7/1.16.8/1.17
* go instrument

# The best way to run the code

We have now offered scripts to execute the code. 

Use `` in case you are Linux/Unix/macOS Working programs and `run.bat` in case you are on Home windows.  Each the information run the instructions silently and prints solely output from the enter file `sample_input/input1.txt`. You're supposed so as to add the enter instructions within the file from the suitable downside assertion. 

Internally each the scripts run the next instructions 

 * `go construct .` - It will construct an executable by the identify geektrust within the listing $GOPATH/src/geektrust moreover the primary.go file .
 * Execute the file from the listing $GOPATH/src/geektrust utilizing the command
`./geektrust sample_input/input1.txt`

We count on your program to take the situation to the textual content file as parameter. Enter must be learn from a textual content file, and output must be printed to the console. The textual content file will include solely instructions within the format prescribed by the respective downside.

This major file, major.go ought to obtain within the command line argument and parse the file handed in. As soon as the file is parsed and the applying processes the instructions, it ought to solely print the output.

 # Working the code for a number of take a look at circumstances

 Please fill `input1.txt` and `input2.txt` with the enter instructions and use these information in `run.bat` or ``. Change `./geektrust sample_input/input1.txt` with `./geektrust sample_input/input2.txt` to run the take a look at case from the second file. 

 # The best way to execute the unit exams

 The unit exams are ran and the protection is calculated utilizing the library `gotestsum`. That is unbiased of your answer and there's no want so as to add any dependency. Nevertheless this may work provided that you employ Go Modules for dependency administration.

We execute the unit exams by operating the next command from the listing $GOPATH/src/geektrust

`gotestsum --hide-summary=all ./...`
We verify for the protection of unit exams by executing the next command. from the listing $GOPATH/src/geektrust

`gotestsum --hide-summary=all -- -coverprofile=cowl.out ./...`

# Assist

You'll be able to refer our assist paperwork [here](
You'll be able to learn construct directions [here](

hello and welcome! Are you certain your path is appropriate? ./geektrust sample_input/input1.txt, doesn’t it lack of a / or ? The clean inside a path should be (with the empty house) Relies on the way you go the trail



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments