Re: [go-nuts] can someone create an example for me of a webpage that can run a bash command ?

2018-02-15 Thread Sebastien Binet
hi Dave,

On Thu, Feb 15, 2018 at 3:56 AM, David Brendlinger <
davidbrendling...@gmail.com> wrote:

> can someone create an example for me of a webpage that can run a bash
> command ?
>
> I would like a index.html that has a button on it.  you hit the button and
> it would do a ls /tmp >> myfile
>

here is something you can start playing with:

```
package main

import (
"flag"
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)

var (
addrFlag = flag.String("addr", ":", "server address:port")
)

func main() {
flag.Parse()
http.HandleFunc("/", helloWorld)
err := http.ListenAndServe(*addrFlag, nil)
if err != nil {
log.Fatal(err)
}
}

func helloWorld(w http.ResponseWriter, r *http.Request) {
cmd := exec.Command("ls", "/tmp")
out, err := cmd.Output()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, ">>> %s\n", strings.Join(cmd.Args, " "))
fmt.Fprintf(w, "%s\n", string(out))
}

```

this will run the "ls" command on the server, not the client, though :)

and I left the button part as an exercize for the reader :P

I am a newby :)
>
welcome!

-s

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] can someone create an example for me of a webpage that can run a bash command ?

2018-02-14 Thread Jonathan Yu
Hi Dave,

I think what you want is to combine net/http (for the server part) with
os/exec (to invoke bash, though with your example you don't need a shell
and could execute the `ls` command directly). You'd need one or two
handlers; maybe browse this to understand more:
https://golang.org/doc/articles/wiki/

It's not specifically what you were asking, but this might be something
that could be done without Go at all, by emulating a full Linux system
entirely in the browser. For example: https://bellard.org/jslinux/

Cheers,

Jonathan

On Wed, Feb 14, 2018 at 6:56 PM, David Brendlinger <
davidbrendling...@gmail.com> wrote:

> can someone create an example for me of a webpage that can run a bash
> command ?
>
> I would like a index.html that has a button on it.  you hit the button and
> it would do a ls /tmp >> myfile
>
> I am a newby :)
>
> Thank you in advance
>
> Dave
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jonathan Yu / *@jawnsy* on LinkedIn ,
Twitter , GitHub ,
Facebook 
*“Ever tried. Ever failed. No matter. Try again. Fail again. Fail better.”* —
Samuel Beckett, Worstward Ho (1983)

“In an adaptive environment, winning comes from adapting to change by
continuously experimenting and identifying new options more quickly and
economically than others. The classical strategist's mantra of sustainable
competitive advantage becomes one of serial temporary advantage.” — Navigating
the Dozens of Different Strategy Options

 (HBR)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] can someone create an example for me of a webpage that can run a bash command ?

2018-02-14 Thread David Brendlinger
can someone create an example for me of a webpage that can run a bash 
command ?  

I would like a index.html that has a button on it.  you hit the button and 
it would do a ls /tmp >> myfile

I am a newby :)

Thank you in advance

Dave  

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.