Linux Terminal befehle ausführen

Hallo. Ich möchte ein Script in golang schreiben, der paar Befehle in Terminal ausführt.
Doch ich habe bis jetzt nur was für Windows gefunden. Ich würde die Befehle in Linux ausführen. Läuft es bei Linux auch wie bei Windows cmd ? Also mit execute.Command()? Oder gibt es das was anderes ?
Vielen dank voraus :slight_smile:

Yes, that should work.

Did your read my Post or you just saw execute.Command() and suspected something ? :slight_smile:

As I’m a German user by myself I read and mostly understand your post, and unless you provide code that fails on Linux I assume that you do it the same way on both OSs.

1 Like

Please stick to english when posting here :slight_smile:

Oh sorry. :slight_smile:

To give confirmation by experience: Yes it does work.
I have the same code running on both Windows and Linux (and WSL for that matter) using exec.Command() and it works just as expected. Of course you have to keep the peculiarities of the different OSes in mind but that should be obvious.

Also from the docs:

Package exec runs external commands. It wraps os.StartProcess […]

Package os provides a platform-independent interface to operating system functionality.

Another note: Since you specifically asked about executing commands in the terminal. :

[…] the os/exec package intentionally does not invoke the system shell and does not expand any glob patterns or handle other expansions, pipelines, or redirections typically done by shells.

So if you’re relying on features of your specific shell, that won’t work (unless you run the shell yourself).

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