Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Java process builder not returning correct (or any) output

 
Bod McLeon
Ranch Hand
Posts: 123
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use the UNIX 'which' command to find where a certain version of python is located.
It should be as simple as doing:

which (,for me,) will return

However, when I try and run this in java process builder, the exact output I get is:

This is the same when I read from both the error stream, and the input stream.
I tried so many variants of this command, such as:

(these output of all of these is the same as shown above)
even going as far as to do:

and, again, other variations of this.
I have tried different methods of splitting the command for process builder, such as:

All of these yield pretty much the exact same output.
However, the moment I do:

It outputs the correct directory fine.


Why is the output different in java? What is going on?

Note: I have also tried them all using:
 
Knute Snortum
Sheriff
Posts: 6551
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post a SSCCE (that's a link) or at least the method with Runtime.getRuntime().exec() and the read from STDOUT in it?  Use .exec("which", "python3"); and post the output.
 
Bod McLeon
Ranch Hand
Posts: 123
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Can you post a SSCCE (that's a link) or at least the method with Runtime.getRuntime().exec() and the read from STDOUT in it?  Use .exec("which", "python3"); and post the output.


Here's the code:

And the output - well - that's non-existent (there is none - nothing is written to the console).
 
Knute Snortum
Sheriff
Posts: 6551
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's weird.  It works fine for me.
 
Knute Snortum
Sheriff
Posts: 6551
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting this line
between lines 13 and 14 and see if you get some error output.
 
Bod McLeon
Ranch Hand
Posts: 123
Mac OS X IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:That's weird.  It works fine for me.


When I do .exec("which", "python"), as I mentioned in the first post, that is fine and I get an output.

Unfortunately putting that line in does not work.

I don't know where your python 3 is located, but mine is installed using PyEnv, so not the default install location. I'm not sure if that could be making any difference.
I decided to try it. My python 3.6 is installed normally under '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6'
I ran .exec("which", "python3.6") but that did not work.
 
Knute Snortum
Sheriff
Posts: 6551
176
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I can think of is that the PATH environment variable is different when you run a Java program than when you run an interactive shell.  Try adding this line to your program:
 
Ron McLeod
Saloon Keeper
Posts: 2870
370
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bod McLeon wrote:And the output - well - that's non-existent (there is none - nothing is written to the console).


Most likely an exception is being thrown, and you are simply ignoring it.  You should at least print the stack.  I would also printout the exit value:

Edit: updated code
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!