All things are lawful, but not all things are profitable.
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.
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:That's weird. It works fine for me.
All things are lawful, but not all things are profitable.
Bod McLeon wrote:And the output - well - that's non-existent (there is none - nothing is written to the console).
Campbell Ritchie wrote:How are you emptying the input and error streams from your Process? Have you combined them into one stream?
I think there is enough similarity to your previous posts that I should combine them into one thread, and this is too difficult a question for the “beginning” forum, so I shall move you to the “general” forum.
Just as well I merged the two discussions.Bod McLeon wrote:. . . It's the same problem again!
Are you creating new Threads to empty those two streams? If not, the error stream may remain full for too long while you empty the input stream. Have you read the article by Michael Daconta called “When Runtime.exec() won't”? It is probably simpler to use a process builder and merge the two streams, but the principle of emptying both streams hasn't changed.Bod McLeon wrote:. . . . . .
Campbell Ritchie wrote:
Are you creating new Threads to empty those two streams? If not, the error stream may remain full for too long while you empty the input stream. Have you read the article by Michael Daconta called “When Runtime.exec() won't”? It is probably simpler to use a process builder and merge the two streams, but the principle of emptying both streams hasn't changed.
Campbell Ritchie wrote: It is probably simpler to use a process builder and merge the two streams
Bod McLeon wrote:I have been doing some research, but I'm not sure how to merge the two streams.
And what's it actually going to change? Surely the output would be the same, but I'm instead only reading one output, rather than 2.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:
Bod McLeon wrote:I have been doing some research, but I'm not sure how to merge the two streams.
redirectErrorStream(true) will make sure all error output (basically System.err) gets redirected (merged) to the standard output (basically System.out).
And what's it actually going to change? Surely the output would be the same, but I'm instead only reading one output, rather than 2.
If you read the article Campbell mentioned, you will see that the process you call will block if either its output buffer or its error buffer is full. In your code, you first try to read all of the output. This loop will only end if the process ends. If it's the error buffer that gets full, the process will block but never end. The first loop will therefore also never end. Your application is now blocked until you either kill the process you called, or your application itself.
By performing the redirect, you only have one stream that contains both normal and error output. The process' buffers will not fill up as long as you keep reading from the single stream.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:I suspect the answer is that the PATH variable is different when you have an interactive shell than when you don't, although on macOS I'm not sure I can help you with that.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Well, I hesitate to begin, because I really don't know masOS. I know Linux and that's the kernel that macOS uses. I know the bash shell, which is part of your environment. Does anyone else know masOS specifically?
Okay, I'll proceed in a very cautious manner. First you need to start a shell. This might be called a command prompt or terminal. Once there, type this:
cat .bashrc
Copy and paste here what is printed on the screen. We'll start from there. (I may be in and out so don't expect an immediate response from me.)
All things are lawful, but not all things are profitable.
Knute Snortum wrote:I'm out of my depth, but let's try a few other things.
Is there a .bashrc or a .bash_login file? Cat those if so.
Cat /etc/profile
What we're looking for is something that determines if you are running an interactive shell. We want to append your Python path to the PATH variable even if the shell is not interactive.
If you try to do this yourself, backup the file first!
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Just a thought before we do all this: What is you original intent? If it's to use the Java program "in the wild", this won't work, because other people's PATH still might not contain the path to Python3. But if it's just the execute a Python3 program from within Java, you can just use the full path to Python3 in your process builder.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:The problem will be that anyone else running the Java program will not have the same environment as you and the execute may fail. I think you should consider why you are calling a Python program from Java at all.
Bod McLeon wrote: I would have created the main processing script in Java, the problem is one of the python libraries I am using is python only, so I had to write the script in python.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
Bod McLeon wrote: I would have created the main processing script in Java, the problem is one of the python libraries I am using is python only, so I had to write the script in python.
I'd be interested in what that library is. You might be able to find a Java library for it.
Don't get me started about those stupid light bulbs. |