Mtools from go script is not working

Unable to use mtools commands inside go script.
"“exit status 2"”

Hi @Aayushi_Mangal,

Can you provide more information on what you are trying to do, including a Go code snippet and relevant software versions?

I suspect you may be referring to using a Go package like exec to invoke one of the mtools Python scripts.

With a better understanding of what you are trying to achieve, there may be an alternative approach to recommend.

Thanks,
Stennie

Hello @Stennie,

With a better understanding of what you are trying to achieve, there may be an alternative approach to recommend.

We wanted to execute mtools like “mloginfo logfilename.log” from the go script, is that possible?

We tried like this:
out, err = exec.Command(“mloginfo /path/to_file/mongo.log”).Output()

output will be:
fork/exec /usr/local/go/bin/mloginfo /path/to_file/mongo.log.log: no such file or directory

Hi @Stennie,

With respect to @Aayushi_Mangal’s reply above, when trying like this
out, err = exec.Command("/bin/bash","-c",“mloginfo /path/to_file/mongo.log”).Output()

we are getting “exit status 2” as error.
Please suggest if any alternate approach for running mtool commands from golang.

Hi @Aayushi_Mangal,

I suspect the issue is that you need to pass arguments like the log file path separately to exec.Command(). The first parameter should only be the name of the command to execute: https://golang.org/pkg/os/exec/#Command.

Regards,
Stennie

1 Like

Hi @Stennie

We tried passing arguments to exec.Command in all ways but we are still getting “exit status 2” while trying to run any mtools command.
Please suggest if any alternate approach for running mtool commands from golang.

Thanks,
Pankaj

Verify existence and write permission of directory /path/to_file/.

I am really surprised that you pass /path/to_file/mongo.log yet the error message specifies /path/to_file/mongo.log.log.

I am really surprised that you pass /path/to_file/mongo.log yet the error message specifies /path/to_file/mongo.log.log .

That is typo, it is path to file, I mentioned that manually.
In short we would like to run mtools utility using golang. please provide any working sample code snipet if you could that will be helpful.

Does it means that the code snippet and the error message you shared is not exactly the one you got?

It is hard to help if what you shared is something you manually typed rather that a real cut-n-paste from real code and real error message. Because we are getting side tracked from the real issue.

I just went and look at the link provided

and indeed your usage is wrong. Try

exec.Command( "mloginfo" ,  "/path/to_file/mongo.log" )

Hi @steevej,

The issue is real, only file and path is changed due to some data security policy.
It would be great help if we get help to execute mtools from golang.
We checked for the file permission also.

I just edited my previous post with some information.