J
jeremy redburn
Hello,
I was wondering if anyone was aware of any limitations of shell
scripts run via java.lang.Runtime.exec? I'm trying to write a simple
Java program that runs a shell script and grabs the resultant output
as XML. For now, I can't even get my program to just take in the
output of the script and send it to stdout. It seems to work fine as
long as I don't have multiply piped lines in the shell script. Does
anyone have any advice?
The relevant part of the Java program:
Runtime rt = Runtime.getRuntime();
try {
Process process = rt.exec(cmd);
InputStream is = process.getInputStream();
byte[] buf = new byte[1024];
int l = 1;
while (l > 0) {
l = is.read(buf);
if (l > 0) {
System.out.write(buf, 0, l);
}
}
} catch (Exception e) {
System.err.println("Error: " + e);
}
myscript.sh just consists of:
#! /bin/sh
echo "Hello and hi" | grep "and" | sed 's/hi/goodbye/'
exit
When I run the Java program I get no output at all and I have to hit
Ctrl-C to regain control.
Thanks much,
Jeremy
I was wondering if anyone was aware of any limitations of shell
scripts run via java.lang.Runtime.exec? I'm trying to write a simple
Java program that runs a shell script and grabs the resultant output
as XML. For now, I can't even get my program to just take in the
output of the script and send it to stdout. It seems to work fine as
long as I don't have multiply piped lines in the shell script. Does
anyone have any advice?
The relevant part of the Java program:
Runtime rt = Runtime.getRuntime();
try {
Process process = rt.exec(cmd);
InputStream is = process.getInputStream();
byte[] buf = new byte[1024];
int l = 1;
while (l > 0) {
l = is.read(buf);
if (l > 0) {
System.out.write(buf, 0, l);
}
}
} catch (Exception e) {
System.err.println("Error: " + e);
}
myscript.sh just consists of:
#! /bin/sh
echo "Hello and hi" | grep "and" | sed 's/hi/goodbye/'
exit
When I run the Java program I get no output at all and I have to hit
Ctrl-C to regain control.
Thanks much,
Jeremy