Wednesday, May 20, 2015

GO Programming Language : Executing external system command using "Go" language

Prerequisite : you must have basic knowledge of how to execute a programming in Go language.
How execute first hello world program.

In following section, we will discuss, how to execute an external program. My goal is, instead of executing a command in terminal, I want to execute using Go programming language.

Source Code:
package main
import (
        "bytes"
        "fmt"
        "log"
        "os/exec"
        "strings"
)

func main() {
        cmd := exec.Command("docker","ps","-a")
        cmd.Stdin = strings.NewReader("")
        var out bytes.Buffer
        cmd.Stdout = &out
        err := cmd.Run()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Output \n",out.String())
}

Output:
Ahh... I got a long list of output as expected.


Description:
In the source, I was trying to execute the following command
docker ps -a
For this, I pass the above command as argument to function "command" as different strings.
When I tried to pass whole command (i.e. docker ps -a) as a single string, it produce an error saying "exec: "docker ps -a": executable file not found in $PATH exit status 1". This means the first argument is the name of the executable file and in order to execute the command it tries to search the file mentioned in first string in function "exec.Command()". Since in my case the actual executable file name is "docker", this couldn't execute the "docker ps -a" command.
So, every word in the command (or the external program we want to execute) must be provided as different string to "exec.Command()".

That's all for now.


-Enjoy


 

GO Programming Language : First day with GO - Executing "Hello world" program.

OS : Ubuntu 12.04


Command to install
sudo apt-get install gccgo-go

Now type "go version" to know the version of  Go.
here is my output
go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64

Now its time to move on to our first hello world program.
Use any editor to create a Go file. Here I am using "vim" editor. Now create a Go file using following command. Depending upon the editor you are using following may differ.
vim hello.go

Now press i to enter INSERT mode and copy the following content

package main
import "fmt"

func main(){
   fmt.Printf("Hello, World\n");
}



Now press ":wq" to save and exit from editor.
Enter following command to run and see the output
go run hello.go

output:




That's all for now.


-Enjoy

Thursday, May 14, 2015

LaTeX : Part - 4 : Examples of Mathematical equations - Advance.

In previous post, we have discussed the basic to write a mathematical equation. In following section we will be discussing on some advance equations.

Some samples on advanced mathematical equation:

Source Code Output
 

Some more to come Some more to come

Friday, May 8, 2015

LaTeX : Part - 4 : Examples of Mathematical equations - Basic.

In following section we will have some examples, how to write mathematical equations in Latex.

Please use following package:
For more information on "amsmath" package, please click here.
Use of $ (Dollar symbol)

$ is generally used in a paragraph, where some part of paragraph such as variables, special symbols etc are required to display in math mode.

Example-1 :
Hello reader, here is the first math equation example. For this $ a + b $ , below is the output.

Output

Example-2 :
Hello reader, here is the first math equation example. For this $$ a + b $$ , below is the output.

Output
 
 Henceforth, we will use $$ instead of $.

Here is list of some sample codes and their output:

Source Code Output

 





Some more to come Some more to come