views:

262

answers:

1

I'm using ColdFusion MX7 to perform a CFEXECUTE on some Java 6 code.

Unfortunately sins CF7 does not work under JDK 6 I must do it this way.

My problem is that when an exception happens in the Java code if I call a printStackTrace on the exception the CFEXECUTE command hangs. Coldfusion eventually times out but the java process continues to hang in the background.

I'm guessing there is some blocking going on but I can't seem to figure out why.

If I don't do a printstacktrace then everything works fine.

The exceptions are WebService exceptions generated with JAXWS from the Oracle Information Rights Management wsdl.

EDIT

I noticed that I am able to call the printStackTrace with a file PrintStream as a parameter and it works fine. So, it looks like the error stream is having troubles.

Here is the Java Code:

public void Execute(){
    AdminUtils AU = AdminUtils.GetInstance();

 AccountServicesPort AA = AU.GetAccountServicesPort(); 

 LicenseServerRef LicSerRef = AU.GetLicenseServerRef();

 User UserToSave = new User();
 UserToSave.setUserName(UserName);
 UserToSave.setFirstName(FirstName);
 UserToSave.setLastName(LastName);
 UserToSave.setEmailAddress(EmailAddress);
 UserToSave.setServer(LicSerRef);

 try{
  AU.LogMessage("Change User: " + UserName + " " + FirstName + " " + LastName + " " + EmailAddress);
  AA.saveChangesToUser(UserToSave);
 }catch(Exception e){
  e.printStackTrace();
 }
}

Here is the ColdFusion call:

<!--- Update the IRM User. --->
<CFEXECUTE name="c:\Program Files\Java\jdk1.6.0_14\bin\javaw.exe"
           arguments="-cp C:\CFusionMX7\Externals\IRM.jar;C:\CFusionMX7\Externals\Config IRMWebServices.UpdateUser #LoginID# #NewFname# #NewLname#"
           timeout="15" 
           variable="OUTPUT">
</CFEXECUTE>
+3  A: 

Yes, cfexecute does not capture stderr. There was a patch to fix this behavior in CF8.

Since you are using 7, try Ben Forta's tip about redirecting stderr to stdout: http://www.forta.com/blog/index.cfm/2006/9/11/A-Couple-Of-CFEXECUTE-Gotchas

Though you may not need it, another good cfexecute tip: http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Utilities

Update: Added Example

<cftry>  
    <cfset argString = '/c "C:\Program Files\Java\jdk1.6.0_13\bin\java.exe" -cp c:\myJar.jar TestStdErr 2>&1'  >  
    <cfexecute name="c:\windows\system32\cmd.exe" 
  arguments="#argString#"    
  outputFile="c:\cfexcuteResults.log" 
  timeout="5" />  
    <cfcatch>  
       <cfdump var="#cfcatch#">  
    </cfcatch>  
</cftry>  

    public class TestStdErr {
       public static void main(String[] args) {
      try {
      // cause a divide by zero exception 
      int a = 0;
      int b = 2 /a;
      }
      catch(Exception e){
      e.printStackTrace();
     }
      }
   }
Leigh
Thanks. I found these earlier. The problem isn't that I need the err stream info. It just hangs when the trace is printed to it.
Tom Hubbard
Leigh
You are correct. Thank you very much.
Tom Hubbard