process.getInputStream() is empty

J

Joana

hello,

I have an external process that I started with runtime.exec().
When I input for the external process per console

If I enter the input data by console to the external process, I get
with process.getInputStream() a
correct expenditure.

*****
the correctly functioning piece of my program's

PrintWriter pw = new PrintWriter(dg_proc.getOutputStream());
pw.println((new BufferedReader(new
InputStreamReader(System.in))).readLine());

byte[] buf;
process.getInputStream().read(buf); // correct expenditure
*****

But if I hand same input as String to the external process over, I
do not get an information from process.getInputStream().read(buf).

*****
not correctly functioning piece

PrintWriter pw = new PrintWriter(dg_proc.getOutputStream());
pw.println("open view V");

than is result: process.getInputStream().available() = 0.
*****

I do not understand, what wrong I make. If someone has a advice, what
it lies, you write please... commodity very nicely!

With best reagards,
Joana
 
G

Gordon Beaton

not correctly functioning piece

PrintWriter pw = new PrintWriter(dg_proc.getOutputStream());
pw.println("open view V");

try setting "autoFlush" in your PrintWriter, like this:

PrintWriter pw = new PrintWriter(dg_proc.getOutputStream(), true);

or flush manually after printing, like this:

pw.flush();
than is result: process.getInputStream().available() = 0.

Don't use available(), use read().

/gordon
 
J

Joana

hello,

thank You for Your answer!
pw.flush();
I made it already before according to the pw.println().It is not
because of it
:(
Don't use available(), use read().
I use it:

int ch;
while( (ch=input.read()) != -1 )
fileWriter.write((char)ch);

I did System.out.println(process.exitValue()). And this is 13. Have
you any idea, which there for error could be?

best regards,
Joana
 
G

Gordon Beaton

I made it already before according to the pw.println().It is not
because of it

I can't really understand your sentence, but println() won't flush
unless you set autoFlush when you create the PrintWriter:

PrintWriter pw = new PrintWriter(dg_proc.getOutputStream(), true);
I did System.out.println(process.exitValue()). And this is 13. Have
you any idea, which there for error could be?

The only "standard" is that non-zero indicates some kind of error.

Either the 13 comes from the external program, in which case you
should check its documentation (or ask the author) to find out what it
means, or it's a Windows error, in which case it means "permission
denied" (according to Google).

/gordon
 
T

Tor Iver Wilhelmsen

I did System.out.println(process.exitValue()). And this is 13. Have
you any idea, which there for error could be?

If it's on Windows "net helpmsg 13" will tell you it's "Illegal data".
This is assuming the program in question uses the standard Windows
exit codes.
 
J

John C. Bollinger

Joana said:
hello,

thank You for Your answer!



I made it already before according to the pw.println().It is not
because of it
:(



I use it:

int ch;
while( (ch=input.read()) != -1 )
fileWriter.write((char)ch);

I did System.out.println(process.exitValue()). And this is 13. Have
you any idea, which there for error could be?

best regards,
Joana

Program return codes are completely program dependent. Check the
program documentation, although this sort of thing often goes
undocumented. You may also want to read the Process' error stream and
output what you find -- this is more likely to contain something useful
to you for troubleshooting.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top