php bash执行,PHP问题集锦 - 使用php exec和javascript执行bash脚本

我试图在下面运行这个javascript,但没有看到php shell_exec命令的输出。

运行测试——bash脚本将输出一系列ID的34535、25643、23262等。当我用一个简单的PHP文件运行它时,它工作得很好。print shell_exec('/opt/bin/echkchunk -a');

但是当我尝试在下面运行它,并选择test1时,没有任何东西输出到屏幕。通过chromes开发人员工具,我可以看到当test1被选择为以下内容时的代码

就好像被注释掉了。

所以我的问题是,是否可以用php和javascript以这种方式运行bash脚本?或者有没有其他方法可以在不使用javascript的情况下将这些信息显示到网页上?

$(document).ready(function() {

$("#selector").on("change", function() {

if ($("#selector").val() == "test1") {

$("#rightselection").css("background-color", "red");

$("#rightselection").html(tester);

}

if ($("#selector").val() == "test2") {

$("#rightselection").css("background-color", "blue");

$("#rightselection").html("test2");

}

if ($("#selector").val() == "test3"){

$("#rightselection").css("background-color", "yellow");

$("#rightselection").html("test3");

}

if ($("#selector").val() == ""){

$("#rightselection").css("background-color", "green");

$("#rightselection").html("This is a Test");

}

});

});

最佳答案:

如果结果是多行的,则需要用转义序列或HTML替换换行标记。尝试替换var tester = '<?php shell_exec("/opt/bin/test -a"); ?>';

具有

var tester = '<?php echo str_replace(PHP_EOL, '
', shell_exec("/opt/bin/test -a")); ?>';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值