在运行build.xml文件时,我正试图从我的ant build.xml文件运行python程序,但我无法将参数传递给python脚本
Python程序检查给定数字的阶乘:
事实.py
#!/usr/bin/python
def factorial(num):
if num == 1:
return num
else:
return num * factorial(num - 1)
num = int(input('Enter a Number: '))
if num < 0:
print 'Factorial cannot be found for negative numbers'
elif num == 0:
print 'Factorial of 0 is 1'
else:
print ('Factorial of', num, 'is: ', factorial(num))
build.xml文件如下所示:
<project name="ant_test" default="python" basedir=".">
<target name="python" >
<exec dir="D:apppython" executable="D:apppythonpython.exe" failonerror="true">
<arg line="D:appant-workoutfact.py/>
</exec>
</target>
当运行build.xml文件时,它运行fact.py-python程序,并期望用户输入检查给定数字的阶乘。
如何将数字从ant build.xml文件传递给python程序
提前感谢!!!!!
根据文件
请注意,您不能与分叉程序交互,向其发送输入的唯一方式是通过和inputstring属性。还要注意,由于Ant 1.6,任何读取分叉程序中输入的尝试都将收到EOF(-1(。这与Ant 1.5有所不同,后者会阻止这种尝试
(强调矿(
那么你能做什么呢?提供以下任一项:
input
从中获取执行命令的标准输入的文件。此属性与inputstring属性互斥。
inputstring
用作已执行命令的输入流的字符串。此属性与输入属性互斥。
示例:
<project name="ant_test" default="python" basedir=".">
<target name="python" >
<exec dir="D:apppython" executable="D:apppythonpython.exe"
failonerror="true"
inputstring="42">
<arg line="D:appant-workoutfact.py/>
</exec>
</target>