无法在phing XML中使用EOF分隔的此处文档 [英] Unable to use here-document delimited by EOF within phing XML
问题描述
切换到其他用户后,我有一些命令要运行.我需要在构建xml文件中执行此操作.
I have some commands to be run after switching to a different user. I need to do this in a build xml file.
以下是我所做的-
<exec command="sudo su auto_deploy << EOF
echo 'Logged in user'
whoami
EOF" dir="${dir.scratchpad}" />
我使用了XML转义,即& lt;
表示<
.
I have used XML escaping, i.e. <
for <
.
但是,我收到以下错误-
However, I am getting the following error -
sh: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
相关问题-此处文档给出了意外的文件结尾"错误
更新
注意-在开始EOF之后和结束EOF之前,我没有放置任何空格.
Note - I have not put any space after the starting EOF and before the ending EOF.
更新1
添加了赏金.期望得到一个详尽的答案,因为到目前为止,我从这些评论中无法理解.请原谅我缺乏知识.
Added bounty. Expecting an elaborate answer because I am unable to make much sense from the comments so far. Pardon my lack of knowledge.
更新2
以防万一,我正在研究Phing,上面提到的XML来自Phing允许用户编写的build xml文件,以完成与部署相关的工作.
Just in case it was not clear, I am working on Phing, and the XML that I mentioned above is from the build xml file that Phing allows a user to write, to do deployment related stuff.
更新3
正如@tripleee引用的问题中提到的那样,我尝试过--
As mentioned in the question referenced by @tripleee, I tried with this -
<exec command="sudo su auto_deploy << EOF${line.separator}echo 'Logged in user'${line.separator}whoami${line.separator}EOF" dir="${dir.scratchpad}" />
,但仍会引发相同的错误.不知道我在想什么.
but it still throws the same error. Not sure what am I missing.
推荐答案
我以前从未使用过phing,但是从文档中看,似乎有两种方法可以解决您的问题.首先,使用 -verbose
选项,如果您在最终的 EOF
之后添加其他换行符,则原始解决方案似乎可以正常工作.也就是说,如果我有这个 build.xml
:
I've never used phing before, but looking at the documentation it looks like there are a couple of ways to solve your problem. First, using the -verbose
option it looks like your original solution might Just Work if you add an additional newline after the final EOF
. That is, if I have this build.xml
:
<?xml version="1.0"?>
<project name="chamilo" default="clean" basedir=".">
<target name="test">
<exec command="sudo -u deploy bash <<EOF${line.separator}echo Logged in user;whoami${line.separator}EOF" />
</target>
</project>
然后我运行 phing-详细测试
,我看到了:
And I run phing -verbose test
, I see:
[exec] Executing command: sudo -u deploy bash <<EOF
echo Logged in user;whoami
EOF 2>&1
sh: line 2: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
[exec] Logged in user
[exec] deploy
[exec] bash: line 2: EOF: command not found
查看所生成脚本的最后一行,如下所示:
Look at the final line of the generated script, which looks like:
EOF 2>&1
如果我添加其他换行符,例如:
If I add an additional newline, like this:
<?xml version="1.0"?>
<project name="chamilo" default="clean" basedir=".">
<target name="test">
<exec command="sudo -u deploy bash <<EOF${line.separator}echo Logged in user;whoami${line.separator}EOF${line.separator}" />
</target>
</project>
然后它就可以工作了:
[exec] Executing command: sudo -u deploy bash <<EOF
echo Logged in user;whoami
EOF
2>&1
[exec] Logged in user
[exec] deploy
这篇关于无法在phing XML中使用EOF分隔的此处文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!