NConvert process returns exit code -2

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: helmut, XnTriq, xnview

Post Reply
Arvind
Posts: 12
Joined: Wed Apr 21, 2010 9:11 am

NConvert process returns exit code -2

Post by Arvind »

Hi,
I am trying to run nConvert command on a input file to convert it into a JPG.
This is being done from a Java program using Runtime class.
Code snippet is as below:

Code: Select all

		Runtime app = Runtime.getRuntime();
		Process proc;
		try
		{
			proc = app.exec(cmd.toString(), null, workingDirectory);
		}

int exitcode = proc.waitFor();
if(exitcode = 0){
 boolean bsucess = true;
}
The variable cmd in this code has the nconvert command line statement.
This code is giving the exitcode value as -2.
What does this exit code represent?
How to fix it?
Please provide information.

Thanks
Arvind
User avatar
xnview
Author of XnView
Posts: 46238
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: NCovert process returns exit code -2

Post by xnview »

exit code is -2, but the convert failed?
Pierre.
Arvind
Posts: 12
Joined: Wed Apr 21, 2010 9:11 am

Re: NCovert process returns exit code -2

Post by Arvind »

Yes, the conversion failed.
User avatar
xnview
Author of XnView
Posts: 46238
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: NCovert process returns exit code -2

Post by xnview »

Arvind wrote:Yes, the conversion failed.
-2 is a global error. What do you see when you exec it?
Pierre.
Arvind
Posts: 12
Joined: Wed Apr 21, 2010 9:11 am

Re: NCovert process returns exit code

Post by Arvind »

I am trying to run nconvert on Linux programmatically.

The subprocess returned with exit code 254.

What does this mean?

The file was not generated.
User avatar
xnview
Author of XnView
Posts: 46238
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: NCovert process returns exit code

Post by xnview »

Arvind wrote:The subprocess returned with exit code 254.
254? strange, there is no such error
Pierre.
User avatar
helmut
Posts: 8704
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: NCovert process returns exit code -2

Post by helmut »

Just had a quick look at your Java code. Shouldn't it say:

Code: Select all

...
if (exitcode == 0) {
 boolean bsucess = true;
}
(please note the "==" for comparison instead of "=" for assignment)? Is your code snippet above complete? I assume that the Runtime.exec(..) call throws an exception which means that calling nconvert failed. The exception is simply ignored because there's no "catch", so you will never know and your exit code is undefined. I *strongly* recommend to add a "catch" block.
icabod
Posts: 3
Joined: Tue Jun 29, 2010 4:23 pm

Re: NCovert process returns exit code

Post by icabod »

xnview wrote:
Arvind wrote:The subprocess returned with exit code 254.
254? strange, there is no such error
I would guess that as NConvert is being run programatically in this instance, then the return code is being put into an unsigned char? 254 == -2 in that case.

Just my input, and probably not helpful :)

'bod
User avatar
xnview
Author of XnView
Posts: 46238
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: NCovert process returns exit code

Post by xnview »

icabod wrote:is being put into an unsigned char? 254 == -2 in that case.
Yes :-) and NConvert return -2 if there is an error in the process. So you can perhaps check the output?
Pierre.
Arvind
Posts: 12
Joined: Wed Apr 21, 2010 9:11 am

Re: NConvert process returns exit code -2

Post by Arvind »

Hi,
I put try-catch block surrounding Runtime.exec() code. It shows the correct error.

Code: Select all

got the exception-->java.io.IOException: Cannot run program ""//data/stacks/nConvert/NConvert/nconvert"" : java.io.IOException: error=2, No such file or directory
The code was trying to run this command:

Code: Select all

Executing the command -->"//data/stacks/nConvert/NConvert/nconvert" -out png -truecolors  -o  "/data/Apparel/apache-tomcat-6.0.18/temp/fcs4973485609669380733/fe8216cf-59e2-4ea2-9f52-fa33c44fc285/generic/Pant_viewable.png" "/data/Apparel/apache-tomcat-6.0.18/temp/fcs4973485609669380733/fe8216cf-59e2-4ea2-9f52-fa33c44fc285/Pant.jpg"
This works perfectly on Windows machine; issue is only on Linux OS.
The error indicates that it could not find the path. I ran the command seperately on Linux OS. It works.

thanks
arvind
User avatar
xnview
Author of XnView
Posts: 46238
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: NConvert process returns exit code -2

Post by xnview »

Arvind wrote: This works perfectly on Windows machine; issue is only on Linux OS.
The error indicates that it could not find the path. I ran the command seperately on Linux OS. It works.
So not an error of NConvert. Here i can't help you more...
Pierre.
User avatar
helmut
Posts: 8704
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: NConvert process returns exit code -2

Post by helmut »

Arvind wrote:I put try-catch block surrounding Runtime.exec() code. It shows the correct error.

Code: Select all

got the exception-->java.io.IOException: Cannot run program ""//data/stacks/nConvert/NConvert/nconvert"" : java.io.IOException: error=2, No such file or directory
The double slashes "//" in your file path look ambiguous to me. Also the quotation marks might cause a problem (just guessing).
Arvind wrote:This works perfectly on Windows machine; issue is only on Linux OS.
The error indicates that it could not find the path. I ran the command seperately on Linux OS. It works.
When running your command manually, did you use the quotation marks, too? This might be a permission problem, does your program have permission to execute "nconvert"?
Post Reply