refactor process.Process to take files

This commit is contained in:
Jae Kwon
2015-10-17 15:13:19 -07:00
parent 10de637496
commit 5102f7a9cb
3 changed files with 26 additions and 44 deletions
+18 -4
View File
@@ -5,21 +5,23 @@ package main
// TODO: Nonrepudiable command log
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"reflect"
"time"
"github.com/tendermint/tendermint/wire"
. "github.com/tendermint/tendermint/cmd/barak/types"
. "github.com/tendermint/tendermint/common"
cfg "github.com/tendermint/tendermint/config"
pcm "github.com/tendermint/tendermint/process"
"github.com/tendermint/tendermint/rpc/server"
"github.com/tendermint/tendermint/wire"
)
const BarakVersion = "0.0.1"
@@ -152,8 +154,13 @@ func StartProcess(wait bool, label string, execPath string, args []string, input
if err != nil {
return nil, fmt.Errorf("Failed to create outputs dir: %v", err)
}
inFile := bytes.NewReader([]byte(input))
outPath := Fmt("%v/outputs/%v_%v.out", barak_.RootDir(), label, time.Now().Format("2006_01_02_15_04_05_MST"))
proc, err := pcm.Create(pcm.ProcessModeDaemon, label, execPath, args, input, outPath)
outFile, err := OpenAutoFile(outPath)
if err != nil {
return nil, err
}
proc, err := pcm.Create(label, execPath, args, inFile, outFile)
if err != nil {
return nil, err
}
@@ -161,7 +168,14 @@ func StartProcess(wait bool, label string, execPath string, args []string, input
if wait {
<-proc.WaitCh
output := pcm.ReadOutput(proc)
// read output from outPath
outputBytes, err := ioutil.ReadFile(outPath)
if err != nil {
fmt.Sprintf("ERROR READING OUTPUT: %v", err)
}
output := string(outputBytes)
// fmt.Println("Read output", output)
if proc.ExitState == nil {
return &ResponseStartProcess{
@@ -260,7 +274,7 @@ func ServeFileHandler(w http.ResponseWriter, req *http.Request) {
http.Error(w, Fmt("Unknown process label: %v", path), 400)
return
}
path = proc.OutputPath
path = proc.OutputFile.(*os.File).Name()
}
file, err := os.Open(path)
if err != nil {
+1 -2
View File
@@ -11,10 +11,10 @@ import (
"sync"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/wire"
btypes "github.com/tendermint/tendermint/cmd/barak/types"
. "github.com/tendermint/tendermint/common"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/wire"
)
func remoteNick(remote string) string {
@@ -268,7 +268,6 @@ func cliListProcesses(c *cli.Context) {
endTimeStr := proc.EndTime.String()
fmt.Printf(", stopped at %v\n", Yellow(endTimeStr))
}
fmt.Printf(" stdout/stderr goes to %v\n", proc.OutputPath)
}
}
}(remote)