簡體   English   中英

PHP的調用bash腳本與多個命令的問題

[英]php calling bash script with multiple commands issue

以下是我的任務演示文件

index.php的內容

shell_exec("./delete.sh param1 params2");

該腳本是可執行的

demo.sh的內容

#! /bin/bash
#! /usr/local/bin/php
destination_path=$1
source_path=$2
xpdf/pdftotext source_path destination_path && php textconv.php destination_path final_output

終端執行demo.sh腳本可以正常運行,並且可以生成所需的輸出, 但通過index.php執行時則不能。

destination_path已生成,但未生成final_output。 有人可以幫忙嗎? &&造成問題嗎?

@GeraldSchneider感謝您的及時評論,它在很大程度上有助於得出結論。

首先 ,我使用的shebang是錯誤的,我必須刪除兩者之間的空間

其次 ,我只能在第一行中使用一個inetrpreter,因此我從那里刪除了php,並在命令中使用了它,如下所示

xpdf/pdftotext source_path destination_path && /usr/local/bin/php textconv.php destination_path final_output

最后出於調試目的,添加2>&1是一個好方法

最終劇本

#!/bin/bash
destination_path=$1
source_path=$2
xpdf/pdftotext source_path destination_path && /usr/local/bin/php textconv.php destination_path final_output

執行為

$output = shell_exec("./delete.sh param1 params2 2>&1");
echo $output;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM