Exec not working

hey, am creating a update feature for my software in which i have to execute linux command in user’s terminal. this is a server based software.
here are the codes
> out2 := exec.Command(“rm -rf /usr/bin/mysoftware && rm -rf /bin/mysoftware”)

  	out2.Run()
  	color.Red.Println("Removed...")
  	color.Green.Println("Getting New File From HBSYS Server...")
  	out3 := exec.Command("wget softwaredownloadlink && chmod +x mysoftware && mv mysoftware /bin")
  	out3.Run()

these commands remove existing files and download new files and move to /bin folder
but these are not working means these commands are executing.
please anyone help me

  1. Check error return values
  2. exec.Comand() takes the executable as first argument, and its arguments in the variadic part of the function call
  3. You can not use shell builtins like &&.
  4. For deleting files/folders you should probably prefer os.Remove/os.RemoveAll
  5. Please use code blocks to format your code.

is there any way to execute that wget command and chmod and mv command ?

The preferred way is to use some equivalent functions from os package like os.File.Chmod() and Client related methods from http package.

In general, try to do as much in go as you possibly can. Do not shell out.

os.Remove("/bin/OKSys")

does this removes the whole /bin folder ?? or just remove the OKSys file

It’s all in the docs.

It removes the single file specified, or if it is a folder, it will remove the folder iff it is empty.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.