How do I keep CFEXECUTE from hanging after a PrintStackTrace

久未见 提交于 2019-11-27 09:48:20

Yes, e.printStackTrace(); writes to stderr (standard error stream). Since cfexecute does not capture stderr, that is probably what is causing cfexecute to hang. There was a patch to fix this behavior in CF8.

Since you are using 7, try Ben Forta's tips about:

Using both /c and 2>&1 should get rid of the hanging problem.

Update: Added Example

ColdFusion Code:

<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>  

Java Class:

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();
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!