Running an OS command using apache-ant to IIS config

China☆狼群 提交于 2019-12-24 08:58:21

问题


I'm trying to create an ANT script which amongst other things will configure IIS.
To do this, trying to harness the appcmd tool. However getting a strange error. The appcmd command runs fine outside of the ant script, but fails within.

I'm using the exec task to kick it all off :

<exec dir="C:\\Windows\\System32\\inetsrv\\" 
executable="C:\\Windows\\System32\\inetsrv\\appcmd.exe" output="d:\out.txt"> 

<arg value="appcmd set config /section:isapiCgiRestriction /+&quot;
[path='${appian_home}\\jakarta\\ISAPI\\isapi_redirect.dll',
description='Jakarta',allowed='True']&quot;" />
</exec>

The output trapped via ANT is :

Object 'APPCMD SET CONFIG /SECTION:ISAPICGIRESTRICTION /+?
[PATH='D:\PTMP2\APPIAN17\\JAKARTA\\ISAPI\\ISAPI_REDIRECT.DLL',
DESCRIPTION='JAKARTA',ALLOWED='TRUE']' is not supported. 
Run 'appcmd.exe /?' to display supported objects.

However when I run If I c&p that command to the dos prompt it will happily run :

C:\Windows\System32\inetsrv>appcmd set config /section:isapiCgiRestriction 
/+"[path='d:\ptmp2\appian17\\jakarta5\\ISAPI\\isapi_redirect.dll',descripti
on='Jakarta',allowed='True']"
Applied configuration changes to section 
"system.webServer/security/isapiCgiRestriction" for 
"MACHINE/WEBROOT/APPHOST" at configuration commit path "M   
ACHINE/WEBROOT/APPHOST"

回答1:


Needs to escaped single quote as well.

Also changed path separate to /

Use below:

<exec executable="cmd.exe" dir="C:/Windows/System32/inetsrv" failonerror="true">
    <arg line="/c appcmd set config /section:isapiCgiRestriction /+&quot;[path=&apos;${appian_home}/jakarta/ISAPI/isapi_redirect.dll&apos;,description=&apos;Jakarta&apos;,allowed=&apos;True&apos;]&quot;"/>
</exec>


来源:https://stackoverflow.com/questions/44627303/running-an-os-command-using-apache-ant-to-iis-config

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