I have a program readfile.go
and I want to give the command line argument os.Args[1]
also as readfile.go
.
However 'go run' thinks that it is an additional argument to itself rather than to the output executable. Is there a flag which can tell 'go run' that this is an argument to executable?
mvaidya@mvaidya-VirtualBox:~/junkeork$ go run readfile.go readfile.go package main: case-insensitive file name collision: "readfile.go" and "readfile.go" mvaidya@mvaidya-VirtualBox:~/junkeork$
Error:
package main: case-insensitive file name collision: "readfile.go" and "readfile.go"
Open a command prompt (Windows+R, type "cmd" and hit enter). Then change to the directory housing your executable ("cd enter-your-directory-here"), and run the command with the parameters.
To access all command-line arguments in their raw format, we need to use Args variables imported from the os package . This type of variable is a string ( [] ) slice. Args is an argument that starts with the name of the program in the command-line. The first value in the Args slice is the name of our program, while os.
Batch parameters (Command line parameters): In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.
If we run this class without any arguments, the output will be as follows. Now, let's pass some arguments to the main class. We have to pass the arguments as space-separated values. Note: If you are using Java 11 or higher, you don't need to compile the java source file explicitly.
You can use --
to separate gofiles from arguments:
go run readfile.go -- readfile.go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With