gomobile - capture stdout/stderr

92 views
Skip to first unread message

Tom Son

unread,
Jun 25, 2025, 12:48:24 PMJun 25
to golang-nuts
I am calling Golang library from Android like that and would like to capture stdout/stderr from my: `Somemodule.functionToCall`.

I was wondering if there is any way to capture the console output.

I am not sure if there is anything builtin to Gomobile that I could use.

I see two potential options:
- capture the stdout/stderr already on the golang level and add the output as a part of the MethodResult,

- capture the stdout/stderr somehow on the Android level? Not really sure if that's possible though

```
private fun rpcCallBackgroundResult(rpcMethod: String?, jsonArguments : String?, result: MethodChannel.Result) {
    object : AsyncTask<Void?, Void?, Void?>() {
        override fun doInBackground(vararg params: Void?): Void? {

            // Here is the call - I would like to capture stdout/stderr
            val response: MethodResult = Somemodule.functionToCall(param1, param2)
            / End

            result.success(response.getOutput())
            return null
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
}
```



Reply all
Reply to author
Forward
0 new messages