問題描述
我正在使用 ColdFusion MX7 對一些 Java 6 代碼執行 CFEXECUTE.
I'm using ColdFusion MX7 to perform a CFEXECUTE on some Java 6 code.
不幸的是,由于 CF7 在 JDK 6 下無法運行,我必須這樣做.
Unfortunately, since CF7 does not work under JDK 6 I must do it this way.
我的問題是,當 Java 代碼中發生異常時,如果我在異常上調用 printStackTrace
,CFEXECUTE 命令會掛起.ColdFusion 最終超時,但 Java 進程繼續在后臺掛起.
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.
如果我不執行 printStackTrace
則一切正常.
If I don't do a printStackTrace
then everything works fine.
異常是使用 JAXWS 從 Oracle 信息權限管理 wsdl 生成的 WebService 異常.
The exceptions are WebService exceptions generated with JAXWS from the Oracle Information Rights Management wsdl.
編輯
我注意到我可以使用文件 PrintStream
作為參數調用 printStackTrace
并且它工作正常.所以,看起來錯誤流有問題.
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.
這里是 Java 代碼:
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();
}
}
這是 ColdFusion 調用:
Here is the ColdFusion call:
<!--- Update the IRM User. --->
<CFEXECUTE name="c:Program FilesJavajdk1.6.0_14injavaw.exe"
arguments="-cp C:CFusionMX7ExternalsIRM.jar;C:CFusionMX7ExternalsConfig IRMWebServices.UpdateUser #LoginID# #NewFname# #NewLname#"
timeout="15"
variable="OUTPUT">
</CFEXECUTE>
推薦答案
是的,e.printStackTrace();
寫入 stderr(標準錯誤流).由于 cfexecute
不捕獲標準錯誤,這可能是導致 cfexecute 掛起的原因.有一個補丁可以修復 CF8 中的這種行為.
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.
由于您使用的是 7,請嘗試 Ben Forta 的提示:
Since you are using 7, try Ben Forta's tips about:
- 將標準錯誤重定向到標準輸出:幾個問題
- 運行命令并在完成后終止的標志:使用 CFEXECUTE 執行命令行實用程序
同時使用 /c
和 2>&1
應該可以解決掛起問題.
Using both /c
and 2>&1
should get rid of the hanging problem.
更新:添加示例
ColdFusion 代碼:
<cftry>
<cfset argString = '/c "C:Program FilesJavajdk1.6.0_13injava.exe" -cp c:myJar.jar TestStdErr 2>&1' >
<cfexecute name="c:windowssystem32cmd.exe"
arguments="#argString#"
outputFile="c:cfexcuteResults.log"
timeout="5" />
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
Java 類:
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();
}
}
}
這篇關于如何在 PrintStackTrace 后保持 CFEXECUTE 不掛起的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!