命令清除批处理文件中的环境 [英] Command clears environment in batch file

查看:133
本文介绍了命令清除批处理文件中的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是批处理文件的新手,如果我在这里没有使用正确的术语,请原谅我。

我有一个批处理文件,需要从所有列出的Glassfish域中取消部署一个特定的应用程序。代码如下:

  @echo off 
setlocal EnableDelayedExpansion
set glassfishDomains = domainA4841,domainB4842

for / d %% a in(%glassfishDomains%)do(
set fullDomain = %% a
set port =!fullDomain:〜-4!
set domain =!fullDomain:〜0,-4!
echo在domain!domain!!port下取消部署appName!
asadmin --host localhost --port!port!undeploy appName
echo。





$ b

问题在于,在执行asadmin命令后,它会失去状态第一次。

  asadmin --host localhost --port!port!取消部署应用程序

为了清楚起见,asadmin.bat是Glassfish的命令行工具。
$ b

如果我从文件中删除此行/命令,则循环会使用延迟扩展来很好地执行字符串提取。这是这种情况下的结果输出:

 取消部署domainA域名应用程序4841 

取消部署应用程序域domainB 4842

通过失去状态,我的意思是变量不再获得正确的值。在执行第一个asadmin命令后,我开始得到以下结果:

 取消域名domainA上的appName 4841 
命令undeploy成功执行。

D:\>(
set fullDomain = domainB4842
set port =!fullDomain:〜-4!
set domain =!fullDomain:〜0, -4!
echo在域中取消部署appName!domain!!port!
asadmin --host localhost --port!port!undeploy appName
echo。

domainB4842
在域!域中取消部署appName! !港口!
CLI136:Port!端口!应该是一个数字值。
命令--host失败。

所以问题是在这些命令执行后是否有办法避免丢失脚本状态 ?或者是这种工具的某种限制(asadmin)?

解决方案

试试

  cmd / Casadmin --host localhost --port!port!undeploy appName


I am new to batch files, so please forgive me if I don't use the proper terminology here.

I have a batch file that needs to undeploy one specific application from all my listed Glassfish domains. Here is the code:

@echo off
setlocal EnableDelayedExpansion
set glassfishDomains=domainA4841,domainB4842

for /d %%a in (%glassfishDomains%) do (
    set fullDomain=%%a
    set port=!fullDomain:~-4!
    set domain=!fullDomain:~0,-4!
    echo Undeploying appName on domain !domain! !port!
    asadmin --host localhost --port !port! undeploy appName
    echo.
) 

The problem is that it is "losing the state" after the asadmin commands is executed for the first time.

asadmin --host localhost --port !port! undeploy app

Just for clarity, asadmin.bat is Glassfish's command line tool.

If I remove this line/command from the file, the loop performs the string extraction just fine, using delayed expansion. This is the resulting output in that case:

Undeploying app on domain domainA 4841

Undeploying app on domain domainB 4842

By "losing state" I mean that variables don't get the correct values anymore. After the first asadmin command execution, I start to get this result:

Undeploying appName on domain domainA 4841
Command undeploy executed successfully.

D:\>(
 set fullDomain=domainB4842
 set port=!fullDomain:~-4!
 set domain=!fullDomain:~0,-4!
 echo Undeploying appName on domain !domain! !port!
 asadmin --host localhost --port !port! undeploy appName
 echo.
)
domainB4842
Undeploying appName on domain !domain! !port!
CLI136: Port !port! should be a numeric value.
Command --host failed.

So the question is if there is a way to avoid "losing the script state" after these commands execute? Or is this some sort of limitation from that tool (asadmin)?

解决方案

Try

cmd /C "asadmin --host localhost --port !port! undeploy appName"

这篇关于命令清除批处理文件中的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆