func ExamplePipeWith() { upper := sh.Cmd("tr", "[:lower:]", "[:upper:]") grep := sh.Cmd("grep") fmt.Print(sh.PipeWith(SWCrawl, grep("far"), upper())) // output: // A LONG TIME AGO, IN A GALAXY FAR, FAR AWAY.... }
func ExamplePipe() { echo := sh.Cmd("echo") // note, you can "bake in" arguments when you create these functions. upper := sh.Cmd("tr", "[:lower:]", "[:upper:]") grep := sh.Cmd("grep") // Equivalent of shell command: // $ echo Hi there! | grep -o Hi | wc -w fmt.Print(sh.Pipe(echo(SWCrawl), grep("far"), upper())) // output: // A LONG TIME AGO, IN A GALAXY FAR, FAR AWAY.... }
func ExampleCmd() { echo := sh.Cmd("echo") fmt.Print(echo("Hi there!")) // output: // Hi there! }
func TestString(t *testing.T) { ex := sh.Cmd("thiswontwork")() s := ex.String() expected := "exec: \"thiswontwork\": executable file not found in $PATH" if s != expected { t.Errorf("expected %q, got %q", expected, s) } }
func ExampleRead() { grep := sh.Cmd("grep") name := "ExampleReadTest" f, cleanup := openTempFile(name, SWCrawl) defer cleanup() fmt.Print(sh.Pipe(sh.Read(f), grep("far"))) // output: // A long time ago, in a galaxy far, far away.... }
func ExampleDump() { grep := sh.Cmd("grep") name := "ExampleDumpTest" defer writeTempFile(name, SWCrawl)() // Equivalent of shell command // $ cat ExampleDumpTest | grep far fmt.Print(sh.Pipe(sh.Dump(name), grep("far"))) // output: // A long time ago, in a galaxy far, far away.... }
func Example_String() { echo := sh.Cmd("echo") executable := echo("Hi there!") // Since we're passing the output into a function expecting a string, we // have to call String() on the output of the command. var s string = executable.String() fmt.Print(s) // output: // Hi there! }