emirc
January 30th, 2004, 05:41 AM
Hi,
I've tried to use Process class to create a utility that would start a native process (tested with Windows diskpart.exe) and to get output and write some commands to the process.
I got into trouble.
I'm using BufferedReader readLine() get the output and writing to process stdin using OutputStream.
Here is the scenario:
1. read all from process intial output
in diskpart.exe this would be
Microsoft DiskPart version 1.0
Copyright (C) 1999-2001 Microsoft Corporation.
On computer: OBJECT
DISKPART>
2. send to process "exit\r\n"
3. get any messages from program on levaing
here this would be
DISKPART> exit
Leaving DiskPart...
So to perform the first step I use the
while((line=bin.readLine()) != null)
condition and inside the loop I simply println(line).
But, the program hangs after reading the first three lines of program output hangs, and the DISKPART> prompt is never read!??!
Anyway, the general question would be:
How to properly communicate with a native process started using Runtime/Process combination?!
Is there a tutorial on the subject somewhere?!
I've tried to use Process class to create a utility that would start a native process (tested with Windows diskpart.exe) and to get output and write some commands to the process.
I got into trouble.
I'm using BufferedReader readLine() get the output and writing to process stdin using OutputStream.
Here is the scenario:
1. read all from process intial output
in diskpart.exe this would be
Microsoft DiskPart version 1.0
Copyright (C) 1999-2001 Microsoft Corporation.
On computer: OBJECT
DISKPART>
2. send to process "exit\r\n"
3. get any messages from program on levaing
here this would be
DISKPART> exit
Leaving DiskPart...
So to perform the first step I use the
while((line=bin.readLine()) != null)
condition and inside the loop I simply println(line).
But, the program hangs after reading the first three lines of program output hangs, and the DISKPART> prompt is never read!??!
Anyway, the general question would be:
How to properly communicate with a native process started using Runtime/Process combination?!
Is there a tutorial on the subject somewhere?!