Can you interface Go with Linux programs?

Say I wanted to stop/run a program like audio-recorder based on some conditions, can Go do this or is this not a thing you would do ie, interface with a “compiled” program that runs.

edit: I might not even actually understand how Selenium works

I’m sort of after something similar to Selenium (the concept) of copying/redoing tasks that someone tells it to do. Click these buttons (not related to the web but using the mouse) or stop/run a program. Maybe command line is closer to what I want. I’ve worked with exec and PHP before.

In order to control a process that is already compiled and running (in other words, you do not have the source code of the process available), this process needs to expose some sort of interface that can be accessed at runtime.

This does not depend on the language you use for the controlling app. (Or only to the extent that this language must be able to access a particular kind of interface.)

I don’t know audio-recorder, but some common options for controlling a running process are:

  • The processe’s internals are available as a library to link against.
  • The running process exposes some means for receiving commands and returning results, like e.g.:
    • stdin and stdout (the classic Unix pipleline feature, think "ps ax | grep httpd`")
    • a TCP connection serving some proprietary remote control protocol
    • an HTTP connection serving a REST API
    • the API of a messaging system (NATS, RabbitMQ, NSQ, nanomsg,…)
    • some proprietary interface (anyone who remembers COM on Windows?)
  • The running process allows to inject external code or otherwise access its internals although no official remote-control interface exists.
  • The controlling process simply stops and re-starts the process, passing a new set of command-line arguments each time.

Regarding Selenium, according to the documentation, it has two options for remote-controlling browsers:

  • Selenium WebDriver accesses the API’s that browsers expose to let them remote-control. Here, the controlled process (the browser in this case) must cooperate by exposing an API to connect against.
  • Selenium-RC injects JavaScript into the current page. This solution is specific to browsers and cannot be generalized to any running process.

So in both cases, the controlled app has to expose some means to let it control from the outside.

If your question is specific to Audio-Recorder, it seems this app exposes an API called “MPRIS D-Bus Interface”. You can find some D-Bus libs at godoc.org but MPRIS seems not widely used with Go.

4 Likes

I don’t know if I’m bridging arbitrary dots here, when thinking for example of an Android application I don’t believe you can “reverse it” once it has been packaged into an APK. I’m wondering if that is the same case when you do the linux-install of ‘apt-get install’ and you run it by command line. If it was a public known source that you could compile yourself maybe you could insert your commands/interrupts/listeners? I definitely am not to that level / not even sure you could do that.

I’m curious if you could listen to it running and detect… Kill with PID assuming it saves upon “crash” I don’t know.

Anyway beyond my scope at this time but I have some information to go on.

Thanks for your time. If I make progress/figure it out in the future I shall return with my approach to the problem.

Edit: With regard to Audio-Recorder, it has a GUI and if I could figure out how to click the stop/record button that would be my interface but would have to see if “clicks” are something you can access with Go. it would be odd though, imagine you’re using your computer and the cursor randomly disappears to click the “stop/record” button.

Yes, it is the same case as with Android apps. Once compiled you are left with the interfaces that the app exposes at runtime.

I agree on the GUI approach. Not only would you interfere with the user’s actions; but also, the code will break when a new version of the app has a different GUI with different UI elements on it.

The best option is to look for any programmatic API that the target app provides.

1 Like

For the GUI approach, give https://github.com/go-vgo/robotgo a try. It claims to support Windows, Mac, and Linux(X11).

2 Likes

Thanks a lot for the help/suggestions, need to go hit the books (internet).

It depends honestly on how much work you would like to do to get this running. In many ways it could be easier to write your own program that makes use of the microphone to record and then encode to some file type you are happy with. All code compiles to machine language, thus you can examine it using the correct tools (debuggers, and things that will parse into assembly).

Here’s a link that explains the process in more detail: https://www.apriorit.com/dev-blog/364-how-to-reverse-engineer-software-windows-in-a-right-way

This is a subject I have been interested in, but you really need to have specialized knowledge for the problem space you are working in.

1 Like

The Audio-Recorder records sound playing that would be outputted to your speakers, if I could find a way to intercept that like Audio-Recorder does. It’s like a DVR for audio. The triggers for recording would be when these events die off / start ie. silence.

Yeah I have to get more familiar/learn I’m definitely “a blank slate”.

Thanks for the link and your response.

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