FAQ
Hi,

I am very new to Golang and so might be doing something totally stupid
here. My goal is to start two processes (java -jar someJar.jar) and then to
  manage communication between them. The problem is that I cannot even get
started with single process and cannot seem to find something that works
for my case. Here is some code sceleton:

func main() {
consumer := exec.Command("java", "jar", "C:\\jars\\target\\my-jar.jar --a")
consumerIn, err := consumer.StdinPipe()
handleError(err)
consumerOut, err := consumer.StdoutPipe()
handleError(err)

// Start
err = consumer.Start()
handleError(err)

consumerRead := bufio.NewReader(consumerOut)
handleError(err)

line, _, err := consumerRead.ReadLine()
handleError(err)* // Error: EOF*
fmt.Println(line)

consumerIn.Write([]byte("bnbban"))

line, _, err = consumerRead.ReadLine()
fmt.Println(line)
}

Basically I am not sure if anything works here, since nothing indicates
that this is.
So just looking for some guidelines, not necessary full solution, but just
how to work with processes basically tail their output and communicate
between them.

Sorry for such non-constructive post, just that I am somewhat confused and
not sure how to specify it in more structural way.

Thanks.


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Kevin Malachowski at Dec 17, 2014 at 5:44 pm
    From just looking at this code nothing jumps out at me as super incorrect (I'm on mobile otherwise I'd check, sorry). What is the output of running your command in the command prompt? If reading from stdout yields an EOF it seems to me that the process exited before it printed anything. Try running a simpler program (ie try running "echo hello world" and if that works then your go code is correct).

    Also, I'm assuming handleError prints the error and exits if its not nil.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Kevin Malachowski at Dec 17, 2014 at 5:46 pm
    Oh, I dont know how bufio.Reader. Try bufio.Scanner, its pretty easy to use and doesn't have the weird return params the Reader does.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tamás Gulácsi at Dec 17, 2014 at 9:36 pm
    "java", "-jar"

    And split the .jar and its arg.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 17, '14 at 5:12p
activeDec 17, '14 at 9:36p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase