我正在编写一个使用表单信息的简单应用程序,将其通过$ _POST传递给执行python脚本并输出结果的PHP脚本.我遇到的问题是我的python脚本实际上并没有运行传入的参数.
process3.php文件:
<?php
$start_word = $_POST['start'];
$end_word = $_POST['end'];
echo "Start word: ". $start_word . "<br />";
echo "End word: ". $end_word . "<br />";
echo "Results from wordgame.py...";
echo "</br>";
$output = passthru('python wordgame2.py $start_word $end_word');
echo $output;
?>
Run Code Online (Sandbox Code Playgroud)
输出:
Start word: dog
End word: cat
Results from wordgame.py...
Number of arguments: 1 arguments. Argument List: ['wordgame2.py']
Run Code Online (Sandbox Code Playgroud)
在wordgame2.py的顶部,我有以下内容(用于调试目的):
#!/usr/bin/env python
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Run Code Online (Sandbox Code Playgroud)
为什么传递的参数数量不是= 3?(是的,我的表单会正确发送数据.)
任何帮助是极大的赞赏!
编辑:我可能会补充说,它确实在我明确告诉它开头和结尾字时运行......这样的事情:
$output = …Run Code Online (Sandbox Code Playgroud) 基本上,我试图编写一个简单的C函数,提示用户输入数组长度,然后要求用户输入数组的值(int).
样本输出所需:
Enter Array Length: 5
Enter values for the array:
1 2 3 6 7
The current array is:
1 2 3 6 7
Run Code Online (Sandbox Code Playgroud)
这是我目前的代码.我觉得好像这应该有效,但是基于C的基本知识,它会导致分段错误.
int intersect()
{
int size, index, input;
printf("Enter the size of the arrays:\n");
scanf("%d", &size);
int arr1[size], arr2[size];
index = 0;
printf("Enter the elements of the first array:\n");
while (index < sizeof(arr1))
{
scanf("%d ", &input);
arr1[index] = input;
index = index + 1;
}
printf("The current array is:\n %d", arr1);
}
Run Code Online (Sandbox Code Playgroud)
我不明白如何收集用户定义的长度数组的输入.任何解释都表示赞赏!