首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从php执行bash脚本

从php执行bash脚本
EN

Stack Overflow用户
提问于 2013-05-05 03:55:05
回答 1查看 268关注 0票数 0

我正在尝试从php脚本中执行bash脚本。

php脚本是:

代码语言:javascript
复制
    <?php

    $clientName = $_POST['clientName'];
    $startDate = $_POST['startDate'];
    $endDate = $_POST['endDate'];
    $mode = $_POST['mode'];

    echo("Current working directory = " . getcwd());
    echo("Client Name = " . $clientName . "<br/>\n");
    echo("Start date = " . $startDate . "<br/>\n");
    echo("End date = " . $endDate . "<br/>\n");
    echo("Mode = " . $mode . "<br/>\n");

    $cmd = "/webroot/argRepeater.bash escapeshellarg($clientName) escapeshellarg($startDate) escapeshellarg($endDate) escapeshellarg($mode)";

echo("Command = " . $cmd . "<br/>\n");
var_dump($cmd);

    exec("/bin/bash ./argRepeater.bash escapeshellarg($clientName) escapeshellarg($startDate) escapeshellarg($endDate) escapeshellarg($mode)", $output, $output2);

    echo("Output array = " . print_r($output) . "<br/>\n");
    echo("Output = " . $output2 . "<br/>\n");

    ?>

上面的php脚本从html表单中获取参数。bash脚本argRepeater.bash只重复提供给它的任何参数。输出如下:

代码语言:javascript
复制
 Current working directory = /home/content/31/10199331/htmlClient Name = yum
    Start date = 2013-05-14
    End date = 2013-05-24
    Mode = fir
   Command = ./argRepeater.bash escapeshellarg(yum) escapeshellarg(2013-05-14) escapeshellarg(2013-05-24) escapeshellarg(fir)
string(128) "./argRepeater.bash escapeshellarg(yum) escapeshellarg(2013-05-14) escapeshellarg(2013-05-24) escapeshellarg(fir)" Array ( ) Output array = 1
    Output = 1  

我的问题:

  1. 要确保执行argRepeater还需要做些什么?
  2. 如何在网页上显示argRepeater的输出?
EN

回答 1

Stack Overflow用户

发布于 2013-05-05 03:58:24

要确保argRepeater获得executed?,还需要做更多的工作

好吧,它需要它所需要的一切。如果你不能确定它是否有效,可以解决你的需求。Output = 1发出信号,它确实在某种意义上执行了某些东西。

  1. How是否要在webpage?

上显示argRepeater的输出

你已经这样做了:

代码语言:javascript
复制
echo("Output array = " . print_r($output) . "<br/>\n");

因此,您还可以询问一些已经由您自己的代码解决的问题。

所以问题可能只是你不确定你是否理解你的代码?如果是这样,只需仔细检查手册中的每一条语句即可。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16378339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档