aspose file tools*
The moose likes Java in General and the fly likes running a .exe from JAVA on Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "running a .exe from JAVA on Linux" Watch "running a .exe from JAVA on Linux" New topic
Author

running a .exe from JAVA on Linux

Elvie D'Souza
Greenhorn

Joined: Feb 22, 2011
Posts: 3
Hi,

I need help in running gdalinfo.exe on LINUX from a JAVA program.

I have all the environment variables set. When I use the following commands, I do not get any output.

List<String> cmds = new ArrayList<String>();
cmds.add("gdalinfo");
cmds.add(param1);
etc

Process proc = new ProcessBuilder(cmds).start();

However, when I open a terminal and run gdalinfo, it executes.

Please help

Thanks
Elvie
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
Welcome to the Ranch

Have you got spaces between the parameters in the command String? I presume using a List will insert the spaces in the correct places.
How are you emptying the Process' input and error streams?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

When Runtime.exec() won't.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Elvie D'Souza
Greenhorn

Joined: Feb 22, 2011
Posts: 3
My code for emptying the streams:

InputStreamReader isr = new InputStreamReader(this.is);
BufferedReader br = new BufferedReader(isr);

String line = null;
while ((line = br.readLine()) != null) {
if (line.length() > 0)
this.sb.append(line).append("\n");
}

I have already gonr through the article "When Runtime.exec() won't" but it has not helped me.

The code runs fine on windows but fails on Linux. Why??

Thanks
Elvie
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10360
    
    8

Elvie D'Souza wrote:
I need help in running gdalinfo.exe on LINUX from a JAVA program.

Exe? As in Windows executable? On Linux???


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87

Exe? As in Windows executable? On Linux???


Elvie is trying to say "gdalinfo" (exe)cutable. Thats quite clear... please dont go after the literal meaning when someone seek help

@Elvie
What is the error you are getting ? Can you give the stacktrace etc.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

It's not quite clear though. .exe is a Windows format, and he's stating he's trying to run it on Linux.
prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87

Stephan van Hulst wrote:It's not quite clear though. .exe is a Windows format, and he's stating he's trying to run it on Linux.


Executable word is not dedicated to any platform.... and there is a gdalinfo utility available for linux. So I thought its clear..
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

I'm sorry Prem, but we need to be nitpickers. If people don't use the proper names and terms for thing, we won't know if they are careful enough to use proper names when it matters. We may understand what he means, a computer doesn't.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

prem pillai wrote:
Stephan van Hulst wrote:It's not quite clear though. .exe is a Windows format, and he's stating he's trying to run it on Linux.


Executable word is not dedicated to any platform.... and there is a gdalinfo utility available for linux. So I thought its clear..


It certainly wasn't clear to me. Especially when one post said this:
Elvie D'Souza wrote:The code runs fine on windows but fails on Linux.

To me this immediately raises the possibility that Elvie expected a Windows executable to run on Linux. Especially when the name of the program was given in Windows format. Of course that might not actually be the case, and it probably isn't because of this:
Elvie D'Souza wrote:However, when I open a terminal and run gdalinfo, it executes.

But there's certainly enough unclarity in the post to point that possibility out.
Elvie D'Souza
Greenhorn

Joined: Feb 22, 2011
Posts: 3
I am sorry for making my post unclear.

@ Prem: I don't get any error. Gdalinfo is used to display the contents/properties of a georeferenced tiff file. When I try running the executable on LINUX, i don't get an output.


prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87

@ Stephan & Paul ; Agree with you guys .... Sorry I think I was behaving very adamant there ...

@Elvie
program just hangs without giving any output OR completes without any output?

Can you please post your complete code?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running a .exe from JAVA on Linux