Thank you so much, I am able to add java path. I also need to add some
other path as well, so Can I do like this:






*os.Setenv("PATH","/home/sdk/jdk-11.0.16/bin:/home/temp/jtreg/bin:$PATH")cmd,err:=exec.Command("java","-version").CombinedOutput()if
err != nil {       fmt.Println(err)}fmt.Println(string(cmd))*



Or Is there any way to add multiple path just we like do with export such
as:
*export PATH=* */home/sdk/jdk-11build/jdk-11.0.16/bin:*
*/home/temp/jtreg/bin:$PATH*

On Thu, Aug 4, 2022 at 11:45 AM Thomas Faughnan <t...@tjf.sh> wrote:

> On Thu Aug 4, 2022 at 12:24 AM EDT, TECHAX wrote:
> > I tried the following one but still, it's not working.
> >
> > *os.Setenv("PATH","/home/sdk/jdk-11.0.16/bin")*
> > *cmd,_:=exec.Command("java","-version").Output()*
> > *fmt.Println(string(cmd))*
> >
> > Since the path is set, so it should display the java version, right?
>
> My guess is because `java -version` prints to standard error instead of
> standard output (at least on my machine). You can verify this by comparing
> the results of `java -version > /dev/null` and `java -version 2> /dev/null`
> in a shell. Some programs choose to print their version to standard output,
> e.g. `go version`. Output() returns the process's standard output and
> possibly an error, but it does not give you the process's standard error.
> CombinedOutput should give you both streams combined, or you could fiddle
> with
> StderrPipe and StdoutPipe.
>
> See here for the details: https://pkg.go.dev/os/exec
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEMj0xqc9BsZMyXCVGjANNbmxTRAPPTDPksyKJ1VXisXdTbSwA%40mail.gmail.com.

Reply via email to