Link to home
Create AccountLog in
Avatar of angelblade27

asked on

Running perl program and get the output in java program

We have a perl program which can't be converted to java without significant developer time which i want to execute in java and get the output in a string. For simplicity sake i was first trying with ls command to see if i can get the output. However nothing is displayed in the console

Process p=Runtime.getRuntime().exec("/usr/bin/ls");
			OutputStream output=p.getOutputStream();

Open in new window

Avatar of CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
read the output (from output) *before* waiting for the process to complete
Process p=Runtime.getRuntime().exec("/usr/bin/ls");
InputStream in=p.getOutputStream();
// read output line by line
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while (null!=(line=in.readLine())) {
Avatar of angelblade27


is it possible to have the command execute in a new shell? Seems that the perl program doesn't run correctly because of some of the environment variables which eclipse may be setting.
It will be a new shell. Can you post the perl?
Unfortunately i can't since it is company specific. All i could say it that it works fine when i run the script from my desktop but fails to find certain modules when executed from the java program
> is it possible to have the command execute in a new shell?

sure, just specify the shell in the command line

sh myscript