【问题标题】:Calling external program with many arguments from website从网站调用带有许多参数的外部程序
【发布时间】:2012-08-29 17:41:23
【问题描述】:

我是网络编程的新手,也许这个问题似乎很明显。我在网站上有一个表格和一个按钮。当按下按钮时,我想调用位于服务器上的外部程序(Linux 可执行文件),并将页面上填写的表单中的所有文本数据作为参数传递给该程序,然后将输出返回给用户。例如:(./myprogram 用户名 userjob ...)。

如何实现?我应该使用什么语言? Javascript、PHP、Python?

谢谢

【问题讨论】:

标签: php html external argument-passing


【解决方案1】:

您可以使用system 调用执行程序,并将用户发布的参数添加到程序末尾。它看起来像这样:

$theResults = system(escapeshellcmd('./myProgram '.$_REQUEST['arguments']));
echo $theResult;

一个完整的工作示例是这样的:

<?php
if(!empty($_REQUEST['arguments'])){
    $results = system(escapeshellcmd('./myProgram '.$_REQUEST['arguments']));
}
?>

<html>
<head>
    <title></title>
</head>
<body>
    <?php
        if(!empty($results)){
            echo $results;
        }
    ?>
    <form method="post" action="">
        Your Arguments: <input type="text" name="arguments" value="" /><input type="submit" name="Submit" value="Submit" />
    </form>
</body>
</html>

【讨论】:

    【解决方案2】:

    你可以简单地使用 php:

    <?php exec("./yourscript.sh");
    

    【讨论】:

    • 我还没有找到如何将多个参数传递给它,你能建议吗?
    猜你喜欢
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多